Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
124405 陈道宁 猫和老鼠 C++ 通过 100 0 MS 252 KB 1041 2024-01-23 14:23:12

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 Map[10]; for(int j=0;j<10;j++){ cin>>Map[j]; } for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ if(Map[i][j]=='C'){ X=i; Y=j; } else if(Map[i][j]=='M'){ x=i; y=j; } } } while(count<100&&(X!=x||Y!=y)){ if(m==0&& x-1>=0 && Map[x-1][y]!='*'){ x--; } else if(m==1&&y+1<10&&Map[x][y+1]!='*'){ y++; } else if(m==2&&x+1<10&&Map[x+1][y]!='*'){ x++; } else if(m==3&&y-1>=0&&Map[x][y-1]!='*'){ y--; } else{ m=(++m)%4; } if(c==0&&X-1>=0&&Map[X-1][Y]!='*'){ X--; } else if(c==1&&Y+1<10&&Map[X][Y+1]!='*'){ Y++; } else if(c==2&&X+1<10&&Map[X+1][Y]!='*'){ X++; } else if(c==3&&Y-1>=0&&Map[X][Y-1]!='*'){ Y--; } else{ c=(++c)%4; } ++count; } printf("%d\n",(X==x&&Y==y)?count:-1); } return 0; }


测评信息: