为什么程序返回值是3 ???
查看原帖
为什么程序返回值是3 ???
1064262
gaikun楼主2024/11/5 18:26
#include<bits/stdc++.h>
using namespace std;
int t,m,n,k,i,j,o,x,y,d,x2,y2,d2,result=0;
char temp;
bool mapp[1010][1010];
bool anss[1010][1010];
int main(){
	freopen("explore.in","r",stdin);
	freopen("explore.out","w",stdout);
	cin>>t;
	for(o=1;o<=t;o++){
		result=0;
		for(i=0;i<=1010;i++){
			for(j=0;j<=1010;j++){
				mapp[i][j]=0;
				anss[i][j]=0;
			}
		}
		cin>>n>>m>>k>>x>>y>>d; 
		anss[x][y]=1;
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				cin>>temp;
				if(temp=='.') mapp[i][j]=0;
				else mapp[i][j]=1;
			}	
		}
		for(i=1;i<=k;i++){
			if(d==0){
				x2=x;
				y2=y+1;
			}
			else if(d==1){
				x2=x+1;
				y2=y;
			}
			else if(d==2){
				x2=x;
				y2=y-1;
			}
			else{
				x2=x-1;
				y2=y;
			}
			if(mapp[x2][y2]==0 && x2>=1 && x2<=n && y2>=1 && y2<=m){
				x=x2;
				y=y2;
				anss[x][y]=1;
			}else{
				d=(d+1)%4;
			}
		}
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
				if(anss[i][j]==1){
					result++;
				} 
		cout<<result<<endl;
		
	} 
	return 0;
}
2024/11/5 18:26
加载中...