Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
120950 黄一航 猫和老鼠 C++ 通过 100 0 MS 244 KB 1226 2024-01-21 14:04:25

Tests(10/10):


#include <bits/stdc++.h> #define int long long using namespace std; int T; char a[15][15]; int dy[] = {0,1,0,-1}; int dx[] = {-1,0,1,0}; signed main() { cin >> T; while (T--) { for (int i = 1; i <= 10; i++) for (int j = 1; j <= 10; j++) { cin >> a[i][j]; while (!(a[i][j] == 'C' || a[i][j] == '.' || a[i][j] == 'M' || a[i][j] == '*')) cin >> a[i][j]; } int stx = 0,sty = 0; int enx = 0,eny = 0; for (int i = 1; i <= 10; i++) for (int j = 1; j <= 10; j++) { if (a[i][j] == 'C') stx = i,sty = j; if (a[i][j] == 'M') enx = i,eny = j; } int dirc = 0,dirm = 0; bool flag = false; for (int i = 1; i <= 100; i++) { int tx = stx + dx[dirc]; int ty = sty + dy[dirc]; if (tx < 1 || ty < 1 || tx > 10 || ty > 10 || a[tx][ty] == '*') dirc = (dirc + 1) % 4; else stx = tx,sty = ty; tx = enx + dx[dirm]; ty = eny + dy[dirm]; if (tx < 1 || ty < 1 || tx > 10 || ty > 10 || a[tx][ty] == '*') dirm = (dirm + 1) % 4; else enx = tx,eny = ty; if (stx == enx && sty == eny) { printf("%lld\n",i); flag = true; break; } } if (!flag) puts("-1"); } return 0; }


测评信息: