50pts求助
查看原帖
50pts求助
878780
WElastkiss楼主2024/11/1 22:44
#include<bits/stdc++.h>
using namespace std;
long long T, n, m, k, x, y, f, ans;
char a[1001][1001], num[1001][1001];
int main(){
	cin >> T;
	for(int i=1; i<=T; i++){
		cin >> n >> m >> k >> x >> y >> f;
		for(int j=1; j<=n; j++){
			for(int l=1; l<=m; l++){
				cin >> a[j][l];
			}
		}
		for(int j=1; j<=k; j++){
			if(f==0){
				if(a[x][y+1]=='.'){
					y+=1;
					//cout << x << ' ' << y << endl;
					num[x][y]='A';
				}else{
					f+=1;
					//cout << "向右转" << endl;
				}
			}else if(f==1){
				if(a[x+1][y]=='.'){
					x+=1;
					//cout << x << ' ' << y << endl;
					num[x][y]='A';
				}else{
					f+=1;
					//cout << "向右转" << endl;
				}
			}else if(f==2){
				if(a[x][y-1]=='.'){
					y-=1;
					//cout << x << ' ' << y << endl;
					num[x][y]='A';
				}else{
					f+=1;
					//cout << "向右转" << endl;
				}
			}else if(f==3){
				if(a[x-1][y]=='.'){
					x-=1;
					//cout << x << ' ' << y << endl;
					num[x][y]='A';
				}else{
					f=0;
					//cout << "向右转" << endl;
				}
			}
//			for(int j=1; j<=n; j++){
//				for(int l=1; l<=m; l++){
//					if(num[i][l]==9){
//						ans++;
//					}
//					cout << num[i][l] << ' ';
//					//num[i][l]=0;
//				}
//				cout << endl;
//			}
//			for(int j=1; j<=n; j++){
//				for(int l=1; l<=m; l++){
//					cout << num[j][l];
//				}
//				cout << endl;
//			}
		}
		//cout << "--------------------------------------------" << endl;
//		for(int j=1; j<=n; j++){
//			for(int l=1; l<=m; l++){
//				cout << num[j][l];
//			}
//			cout << endl;
//		}
		for(int j=1; j<=n; j++){
			for(int l=1; l<=m; l++){
				if(num[j][l]=='A'){
					ans++;
					num[j][l]=' ';
				}
			}
			
		}
		cout << ans+1 << endl;
		//cout << "--------------------------------------------" << endl;
		ans=0;
		for(int j=1; j<=n; j++){
			for(int l=1; l<=m; l++){
				a[j][l]=' ';
			}
		}
	}
	return 0;
}
2024/11/1 22:44
加载中...