2.4.1

来源:互联网 发布:金数据登录网址 编辑:程序博客网 时间:2024/04/29 18:13
/*ID:18861501LANG:C++TASK:ttwo*//*------------------Header Files------------------*/#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <cstdlib>#include <ctype.h>#include <cmath>#include <stack>#include <queue>#include <map>#include <vector>#include <limits.h>using namespace std;/*------------------Definitions-------------------*/#define LL long long#define PI acos(-1.0)#define INF 0x3F3F3F3F#define MOD 9901/*---------------------Work-----------------------*/const int MAX=1000000;  //定义最大的移动步数int maze[10][10];  //这种题目不能从1开始,因为要取模int dx[]={-1,0,1,0};  //四个方向int dy[]={0,1,0,-1};int cd=0,cx,cy;int fd=0,fx,fy;void work(){memset(maze,0,sizeof(maze));char ch;for(int i=0;i<10;i++){for(int j=0;j<10;j++){scanf("%c",&ch);if(ch=='*') maze[i][j]=1;else if(ch=='F') fx=i,fy=j;else if(ch=='C') cx=i,cy=j;}getchar();}int cnt=0,x,y;while(cnt!=MAX){x=cx+dx[cd],y=cy+dy[cd];if(maze[x][y]==1||x<0||x>9||y<0||y>9)cd=(cd+1)%4;else cx=x,cy=y;x=fx+dx[fd],y=fy+dy[fd];if(maze[x][y]==1||x<0||x>9||y<0||y>9)fd=(fd+1)%4;else fx=x,fy=y;cnt++;if(cx==fx&&cy==fy) break;}if(cnt==MAX) printf("0\n");else printf("%d\n",cnt);}/*------------------Main Function------------------*/int main(){//freopen("test.txt","r",stdin);freopen("ttwo.out","w",stdout);freopen("ttwo.in","r",stdin);work();return 0;}

0 0
原创粉丝点击