Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
123350 | 余冠学 | 猫和老鼠 | C++ | 解答错误 | 40 | 0 MS | 260 KB | 2020 | 2024-01-22 21:10:31 |
# include <iostream> using namespace std; int main(){ int qwerty; cin >> qwerty; for (int qwertyuiop = 0;qwertyuiop < qwerty;qwertyuiop++){ char map[11][11]; int cat_x,cat_y,mouse_x,mouse_y,cat_move = 1,mouse_move = 1; for (int i = 0;i < 10;i++){ for (int j = 0;j < 10;j++){ cin >> map[i][j]; if (map[i][j] == 'C'){ cat_x = i,cat_y = j; }else if (map[i][j] == 'M'){ mouse_x = i,mouse_y = j; } } }/* 说明(留给自己看的) XXX_move 是移动方向, 1 代表 向上 (x--) 2 代表 向下 (x++) 3 代表 向左 (y--) 4 代表 向右 (y++) */bool wujie = true; int second = 1; for (;second <= 100;second++){ if (cat_move == 1){ if (cat_x - 1 < 0) cat_move = 4; else if (map[cat_x - 1][cat_y] == '*') cat_move = 4; else cat_x--; }else if (cat_move == 2){ if (cat_x + 1 >= 10) cat_move = 3; else if (map[cat_x + 1][cat_y] == '*') cat_move = 3; else cat_x++; }else if (cat_move == 3){ if (cat_y - 1 < 0) cat_move = 1; else if (map[cat_x][cat_y - 1] == '*') cat_move = 1; else cat_y--; }else{ if (cat_y + 1 >= 10) cat_move = 2; else if (map[cat_x][cat_y + 1] == '*') cat_move = 2; else cat_y++; }if (mouse_move == 1){ if (mouse_x - 1 < 0) mouse_move = 4; else if (map[mouse_x - 1][mouse_y] == '*') mouse_move = 4; else mouse_x--; }else if (mouse_move == 2){ if (mouse_x + 1 >= 10) mouse_move = 3; else if (map[mouse_x + 1][mouse_y] == '*') mouse_move = 3; else mouse_x++; }else if (mouse_move == 3){ if (mouse_y - 1 < 0) mouse_move = 1; else if (map[mouse_x][mouse_y - 1] == '*') mouse_move = 1; else mouse_y--; }else{ if (mouse_y + 1 >= 10) mouse_move = 2; else if (map[mouse_x][mouse_y + 1] == '*') mouse_move = 2; else mouse_y++; }if (cat_x == mouse_x && cat_y == mouse_y){ wujie = !wujie; break; } }if (wujie) cout << -1; else cout << second; }return 0; }