网易游戏2016实习生招聘在线笔试 推箱子
来源:互联网 发布:专业网络投融资平台 编辑:程序博客网 时间:2024/04/28 10:37
这两天又回顾了一下这个题目,整理之后做个保存吧,中间还有点问题,有时间再来改正,自己顺着思路一点点写下来的,逻辑比较简单。
//计算当前的位置int *findPosition(char **a, int sign, int M, int N){ int *position = new int[2]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (sign == a[i][j]) { position[0] = i; position[1] = j; } } } return position;}//刷新现在的位置void refresh(int *person, int *box, int *destination, char **a, int M, int N){ for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { a[i][j] = '0'; } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (i == person[0] && j == person[1]) { a[i][j] = '1'; } else if (i == box[0] && j == box[1]) { a[i][j] = '3'; } else if (i == destination[0] && j == destination[1]) { a[i][j] = '2'; } } }}char **moveOneStep(char **a, char move, int M, int N){ int *person = new int[2]; int *destination = new int[2]; int *box = new int[2]; person = findPosition(a, '1', M, N); destination = findPosition(a, '2', M, N); box = findPosition(a, '3', M, N); if (move == 'r') { //单独一个人向右移 if (person[1] + 1 != M&&!(person[1] == box[1] - 1 && person[0] == box[0])) { person[1] += 1; refresh(person, box, destination, a, M, N); }//人和箱子一起右移,箱子到达就不能在移动 else if (person[1] == box[1] - 1 && person[0] == box[0] && box[1] + 1 != M&&!(box[0] == destination[0] && box[1] == destination[1])) { person[1] += 1; box[1] += 1; refresh(person, box, destination, a, M, N); } } else if (move == 'd') { //单独一个人向下移 if (person[0] + 1 != N&&!(person[0] == box[0] - 1 && person[1] == box[1])) { person[0] += 1; refresh(person, box, destination, a, M, N); }//人和箱子一起下移 else if (person[0] == box[0] - 1 && person[1] == box[1] && box[0] + 1 != N&&!(box[0] == destination[0] && box[1] == destination[1])) { person[0] += 1; box[0] += 1; refresh(person, box, destination, a, M, N); } } else if (move == 'l') { //单独一个人向左移 if (person[1] - 1 != -1 && !(person[1] == box[1] + 1 && person[1] == box[1])) { person[1] -= 1; refresh(person, box, destination, a, M, N); }//人和箱子一起左移 else if (person[1] == box[1] + 1 && person[1] == box[1] && box[1] - 1 != -1 && !(box[0] == destination[0] && box[1] == destination[1])) { person[1] -= 1; box[1] -= 1; refresh(person, box, destination, a, M, N); } } else if (move == 'u') { //单独一个人向上移 if (person[0] - 1 != -1 && !(person[0] == box[0] + 1 && person[0] == box[0])) { person[0] -= 1; refresh(person, box, destination, a, M, N); }//人和箱子一起上移 else if (person[0] == box[0] + 1 && person[0] == box[0] && box[0] - 1 != -1 && !(box[0] == destination[0] && box[1] == destination[1])) { person[0] -= 1; box[0] -= 1; refresh(person, box, destination, a, M, N); } } return a;}int _tmain(int argc, _TCHAR* argv[]){ int M, N, S;//N行数,M列数 cin >> M >> N; cin >> S;//测试数 char **a = new char*[N]; for (int i = 0; i < N; i++) a[i] = new char[M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> a[i][j]; } } //多次循环,做保存用 char **b = new char*[N]; for (int i = 0; i < N; i++) b[i] = new char[M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { b[i][j]=a[i][j]; } } //记录初始的目的地位置 int *destination = new int[2]; destination = findPosition(a, '2', M, N); char c_cin; int sum; string direction; int i = 0; while (S--){ //将a置为原始数据 for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { a[i][j] = b[i][j]; } } cin >> sum; while (sum--) { cin >> c_cin; direction.push_back(c_cin); } string::iterator dir_iter; while (direction.size() != 0) { dir_iter = direction.begin(); char move = *dir_iter; direction.erase(dir_iter); //开始进行主判断 a=moveOneStep(a, move, M, N); } //判断最后的修改结果 int *box = new int[2]; box = findPosition(a, '3', M, N); if (destination[0] == box[0] && destination[1] == box[1]) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0;}输入:5 4 3000001300000200000004 rurd6 urdldr6 rrrurd输出:YESYESNO
`
0 0
- 网易游戏2016实习生招聘在线笔试 推箱子
- 网易游戏2016实习生招聘在线笔试:A 推箱子
- 网易游戏2016实习生招聘笔试题目--推箱子
- 网易游戏2016实习生招聘在线笔试——题目1 : 推箱子
- 网易游戏2016研发实习生招聘在线编程题目 推箱子
- 2017网易游戏雷火盘古实习生招聘笔试真题:推箱子 [python]
- 网易游戏2016实习生招聘笔试题目--井字棋
- 【网易游戏】推箱子
- 网易互娱2017实习生招聘游戏研发工程师在线笔试第二场(图像处理)
- 网易互娱2017实习生招聘游戏研发工程师在线笔试第二场(神奇的数)
- 网易笔试题 推箱子
- 网易互娱2017实习生招聘在线笔试(一)
- 网易互娱2017实习生招聘在线笔试(二)
- 网易互娱2017实习生招聘在线笔试(三)
- 网易互娱2017实习生招聘在线笔试(一)
- 网易互娱2017实习生招聘游戏研发工程师在线笔试第二场(一起消消毒)
- 网易游戏2016在线笔试
- 【面试笔试算法】Program 5 : 推箱子 (网易游戏笔试题)
- VC与JavaScript交互(一) -- 调用JS函数
- [Leetcode] 141. Linked List Cycle
- iOS开发UI篇—Quartz2D使用(图形上下文栈)
- Android全屏及屏幕切换
- 演化理解 Android 异步加载图片
- 网易游戏2016实习生招聘在线笔试 推箱子
- JAVA基础 ---- 注释、关键字、常量、变量、位运算符
- [Leetcode] 142. Linked List II
- 11.1 I/O模型概览
- POJ 1363 Rails
- 2015-4-13_OC
- 动态规划NM---滑雪问题
- hdu 2768 Cat vs. Dog(二分图最大匹配--最大独立点集)
- stm32 CT117E之按键(扫描)