why TLE?
查看原帖
why TLE?
1285950
4041nofoundGeoge楼主2024/10/26 14:32
#include<bits/stdc++.h>
using namespace std;
char s[1005][1005];
bool vis[1005][1005];
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int n,m,k,x0,d0,y0;
int main(){
	//freopen("explore.in","r",stdin);
	//freopen("explore.out","w",stdout);
	std::ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--){
		memset(vis,0,sizeof(vis));
		memset(s,0,sizeof(s));		
		cin>>n>>m>>k>>x0>>y0>>d0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>s[i][j];
		int cnt=1;
		int now=d0,nx=0,ny=0;
		vis[nx][ny]=1;
		for(int i=1;i<=k;i++){
			if(k<=0)break;
			int tx=dx[now]+nx,ty=dy[now]+ny;
			if(tx<=n&&tx>=1&&ty<=m&&ty>=1&&s[tx][ty]!='x'&&vis[tx][ty]==0){
				cnt++;
				nx=tx,ny=ty;
				vis[nx][ny]=1;
			}
			else{
				now=(now+1)%4;
				i-=1;
			}
		}
		cout<<cnt<<"\n";
	}
	return 0;
}

2024/10/26 14:32
加载中...