1 条题解
-
1
#include<iostream> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; char arr[15][15]; int del[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; int cx,cy,fx,fy; int main(){ for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ cin >> arr[i][j]; if(arr[i][j] == 'C'){ cx = i; cy = j; } if(arr[i][j] == 'F'){ fx = i; fy = j; } } } int tmpx,tmpy,df=0,dc=0; for(int i=1;i<=1000;i++){ tmpx = cx+del[dc][0]; tmpy = cy+del[dc][1]; if(tmpx>=1&&tmpx<=10&&tmpy>=1&&tmpy<=10&&arr[tmpx][tmpy]!='*'){ cx = tmpx; cy = tmpy; }else dc = (dc+1)%4; tmpx = fx+del[df][0]; tmpy = fy+del[df][1]; if(tmpx>=1&&tmpx<=10&&tmpy>=1&&tmpy<=10&&arr[tmpx][tmpy]!='*'){ fx = tmpx; fy = tmpy; }else{ df = (df+1)%4; } if(cx==fx&&cy==fy){ cout << i; return 0; } } cout << 0; return 0; }
- 1
信息
- ID
- 517
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 3
- 标签
- 递交数
- 9
- 已通过
- 4
- 上传者