66分求助,WA 1 5 9
查看原帖
66分求助,WA 1 5 9
566903
福明o7楼主2022/3/22 13:06
#include<bits/stdc++.h>
#define resh_umbrella return 0
using namespace std;
char c[15][15];
bool t[15][15][5];
int x1;
int y;
int x2;
int y2;
int to1=1;
int to2=1;
int main(){
	memset(t,0,sizeof(t));
	for(int i=1;i<=10;i++){
		for(int j=1;j<=10;j++){
			cin>>c[i][j];
			if(c[i][j]=='C'){
				x1=i;
				y=j;
			}
			if(c[i][j]=='F'){
				x2=i;
				y2=j;
			}
		}
	}
	int ans=0;
	while(1){
		if(x1==x2&&y==y2){
			printf("%d\n",ans);
			resh_umbrella;
		}
		if(t[x2][y2][to2]){
			printf("%d\n",0);
			resh_umbrella;
		}
		t[x2][y2][to2]=1;
		if(to1==1){
			if(c[x1-1][y]=='*'||x1-1<1){
				to1++;
			}
			else{
				x1--;
			}
		}
		else{
			if(to1==2){
				if(c[x1][y+1]=='*'||y+1>10){
					to1++;
				}
				else{
					y++;
				}
			}
			else{
				if(to1==3){
					if(c[x1+1][y]=='*'||x1+1>10){
						to1++;
					}
					else{
						x1++;
					}
				}
				else{
					if(to1==4){
						if(c[x1][y-1]=='*'||y-1<1){
							to1=1;
						}
						else{
							y--;
						}
					}						
				}
			}			
		}
		if(to2==1){
			if(c[x2-1][y2]=='*'||x2-1<1){
				to2++;
			}
			else{
				x2--;
			}
		}
		else{
			if(to2==2){
				if(c[x2][y2+1]=='*'||y2+1>10){
					to2++;
				}
				else{
					y2++;
				}
			}
			else{
				if(to2==3){
					if(c[x2+1][y2]=='*'||x2+1>10){
						to2++;
					}
					else{
						x2++;
					}
				}
				else{
					if(to2==4){
						if(c[x2][y2-1]=='*'||y2-1<1){
							to2=1;
						}
						else{
							y2--;
						}
					}						
				}
			}			
		}		
		ans++;
	}
	resh_umbrella;
}

不知道哪里错了,求改正

2022/3/22 13:06
加载中...