网易游戏服务端(2018.9.8 一定要复习呀 ~)
题目:
解答:
题目:
解答:
答案 1,3
http://blog.aijc.net/server/2015/11/12/HTTP%E5%8D%8F%E8%AE%AE206%E7%8A%B6%E6%80%81%E7%A0%81
http://mrpeak.cn/blog/http-constitution/
https://www.cnblogs.com/panie2015/p/5885922.html
题目:
解答:
题目:
解答:
五个都是
https://www.cnblogs.com/kex1n/p/5233821.html
题目:
解答:
题目:
解答:
题目:
解答:
https://blog.csdn.net/fx677588/article/details/70767446
题目:
解答:
https://blog.csdn.net/drdairen/article/details/73480570 这个博客写得很好,一定要看看呀
同步,是一种特殊的互斥
题目:
解答:
答案 D
https://blog.csdn.net/misayaaaaa/article/details/73826584
https://blog.csdn.net/xiamentingtao/article/details/48242487
网易雷火2017实习生招聘笔试题
1、给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”。比如字符串AAAABCCDAA会被编码成4A1B2C1D2A。
输入描述:
每个测试输入包含1个测试用例 每个测试用例输入只有一行字符串,字符串只包括大写英文字母,长度不超过10000。
输出描述:
输出编码后的字符串
输入例子1:
AAAABCCDAA
输出例子1:
4A1B2C1D2A
思路:从前往后依次查看当前字符是否和下一个字符相等,如果相等,则累计,不等,则输出(在输入的最末位加一个空字符“\0”,方便考察,否则还要为末尾的字符而分情况讨论,导致代码长度增加)
#include<iostream>
#include<string>
void change_style(std::string input) {
int calculate = 1;
input = input + '\0';
for (size_t i = 0; i < input.length(); i++) {
if (input[i] == input[i + 1]) {
calculate++;
}
else {
std::cout << calculate << input[i];
calculate = 1;
}
}
}
int main() {
std::string input;
std::cin >> input;
change_style(input);
return 0;
}
2、最大和
在一个N*N的数组中寻找所有横,竖,左上到右下,右上到左下,四种方向的直线连续D个数字的和里面最大的值
输入描述:
每个测试输入包含1个测试用例,第一行包括两个整数 N 和 D : 3 <= N <= 100 1 <= D <= N 接下来有N行,每行N个数字d: 0 <= d <= 100
输出描述:
输出一个整数,表示找到的和的最大值
输入例子1:
4 2
87 98 79 61
10 27 95 70
20 64 73 29
71 65 15 0
输出例子1:
193
https://www.nowcoder.com/question/next?pid=4111169&qid=76265&tid=18439032
明天再做吧 2018.9.10 3:53
3、推箱子
大家一定玩过“推箱子”这个经典的游戏。具体规则就是在一个N*M的地图上,有1个玩家、1个箱子、1个目的地以及若干障碍,其余是空地。玩家可以往上下左右4个方向移动,但是不能移动出地图或者移动到障碍里去。如果往这个方向移动推到了箱子,箱子也会按这个方向移动一格,当然,箱子也不能被推出地图或推到障碍里。当箱子被推到目的地以后,游戏目标达成。现在告诉你游戏开始是初始的地图布局,请你求出玩家最少需要移动多少步才能够将游戏目标达成。
输入描述:
每个测试输入包含1个测试用例
第一行输入两个数字N,M表示地图的大小。其中0<N,M<=8。
接下来有N行,每行包含M个字符表示该行地图。其中 . 表示空地、X表示玩家、*表示箱子、#表示障碍、@表示目的地。
每个地图必定包含1个玩家、1个箱子、1个目的地。
输出描述:
输出一个数字表示玩家最少需要移动多少步才能将游戏目标达成。当无论如何达成不了的时候,输出-1。
输入例子1:
4 4
....
..*@
....
.X..
6 6
...#..
......
#*##..
..##.#
..X...
.@#...
输出例子1:
3
11
思路:BFS宽度优先搜索。分别考察当前位置上下左右四个方向的情况,用四维数组记录人物移动到当前位置所走的步数。BFS搜索找到的第一个可以将箱子移动到指定位置的步数,即为人将箱子推到指定地点的最少步数(因为同时考虑了四个方向的移动情况)
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct State
{
int human_x;
int human_y;
int box_x;
int box_y;
State(int humanX = 0, int humanY = 0, int boxX = 0, int boxY = 0)
: human_x(humanX), human_y(humanY), box_x(boxX), box_y(boxY) {}
};
//输出结果
void calculate(int N,int M,int human_x, int human_y, int box_x, int box_y, int end_x, int end_y, vector<vector<char>> map) {
queue<State> que;
que.push(State(human_x, human_y, box_x, box_y));
int count[9][9][9][9] = { 0 };
int stepX[4] = { 1, -1, 0, 0 };
int stepY[4] = { 0, 0, 1, -1 };
while (que.size())
{
State cur = que.front();
que.pop();
//推到了要求的位置
if (cur.box_x == end_x && cur.box_y == end_y) {
cout << count[cur.human_x][cur.human_y][cur.box_x][cur.box_y] << endl;
return;
}
//对于人的每个位置,考虑他上下左右四个方向的移动情况
for (int i = 0; i < 4; ++i)
{
State next = cur;
next.human_x += stepX[i];
next.human_y += stepY[i];
//如果人在边界外
if (next.human_x < 0 ||
next.human_x >= N ||
next.human_y < 0 ||
next.human_y >= M ||
map[next.human_x][next.human_y] == '#')
continue;
//如果人走到了箱子的位置(说明此时对箱子进行了向前推进),则箱子也按人走的方向移动一步
if (next.human_x == next.box_x &&
next.human_y == next.box_y) {
next.box_x += stepX[i];
next.box_y += stepY[i];
if (next.box_x < 0 ||
next.box_x >= N ||
next.box_y < 0 ||
next.box_y >= M ||
map[next.box_x][next.box_y] == '#')
continue;
}
//如果之前遍历过,则不再遍历
if (count[next.human_x][next.human_y][next.box_x][next.box_y])
continue;
//没有挪到要求的位置,累计步数加1
count[next.human_x][next.human_y][next.box_x][next.box_y] =
count[cur.human_x][cur.human_y][cur.box_x][cur.box_y] + 1;
que.push(next);
}
}
cout << -1 << endl;
}
//初始化
void init() {
int N = 0, M = 0;
cin >> N >> M;
vector<vector<char>> map(N, vector<char>(M, '0'));
int human_x = 0, human_y = 0, box_x = 0, box_y = 0;
int end_x = 0, end_y = 0;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < M; ++j)
{
cin >> map[i][j];
if (map[i][j] == 'X')
{
human_x = i;
human_y = j;
}
else if (map[i][j] == '*') {
box_x = i;
box_y = j;
}
else if (map[i][j] == '@') {
end_x = i;
end_y = j;
}
}
}
calculate(N, M, human_x, human_y, box_x, box_y, end_x, end_y, map);
}
int main()
{
init();
return 0;
}
2015网易游戏校园招聘笔试题游戏插件研发岗
题目:
解答:
题目:
解答:
答案 D
题目:
解答:
题目:
解答:
题目:
解答:
(四年前学的线性检测,现在居然还记得,佩服自己的记忆力)
题目:
解答:
题目:
解答:
题目:
解答:
今天白天没事的时候,做一下字符串反转的那道编程题。。。。。。。。。。。。。。。。。。。