Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
123817 刘嘉乐 猫和老鼠 C++ 通过 100 0 MS 256 KB 1171 2024-01-23 09:55:27

Tests(10/10):


#include <bits/stdc++.h> using namespace std; int main(){ int n, x, y, X, Y; cin >> n; for(int k = 0; k < n; k++){ int m = 0, c = 0, count = 0; string a[10]; for(int j = 0; j < 10; j++){ cin >> a[j]; } for(int i = 0; i < 10; i++){ for(int j = 0; j < 10; j++){ if(a[i][j] == 'C'){ X = i; Y = j; } else if(a[i][j] == 'M'){ x = i; y = j; } } } while(count < 100 && (X != x || Y != y)){ if(m == 0 && x - 1 >= 0 && a[x - 1][y] != '*'){ x--; } else if(m == 1 && y + 1 < 10 && a[x][y + 1] != '*'){ y++; } else if(m == 2 && x + 1 < 10 && a[x + 1][y] != '*'){ x++; } else if(m == 3 && y - 1 >= 0 && a[x][y - 1] != '*'){ y--; } else { m = (++m)% 4; } if(c == 0 && X - 1 >= 0 && a[X - 1][Y] != '*'){ X--; } else if(c == 1 && Y + 1 < 10 && a[X][Y + 1] != '*'){ Y++; } else if(c == 2 && X + 1 < 10 && a[X + 1][Y] != '*'){ X++; } else if(c == 3 && Y - 1 >= 0 && a[X][Y - 1] != '*'){ Y--; } else { c = (++c) % 4; } ++count; } cout << ((X == x && Y == y) ? count : -1) << endl; } return 0; }


测评信息: