Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
144690 | 陈家宝 | 猫和老鼠 | C++ | 通过 | 100 | 0 MS | 248 KB | 1092 | 2024-04-26 13:14:29 |
#include<bits/stdc++.h> using namespace std; char a[15][15]; int dy[] = {0,1,0,-1},T,dx[] = {-1,0,1,0}; int 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,enx = 0,eny = 0,dirc = 0,dirm = 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; } bool flag = false; for (int i = 1; i <= 100; i++){ int tx = stx + dx[dirc],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; }