Eva_91418 @ 2024-10-26 19:01:46
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
string mapp[1005];
int vis[1005][1005];
void sweep(int m,int n)
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
vis[i][j]=0;
}
}
signed main()
{
cin>>t;
while(t--)
{
int ans=1;
int n,m,k;
cin>>n>>m>>k;
int x,y,d;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
{
cin>>mapp[i];
mapp[i]='W'+mapp[i];
}
while(k--)
{
int dx=x,dy=y;
if(d==0)dy=dy+1;
if(d==1)dx=dx+1;
if(d==2)dy=dy-1;
if(d==3)dx=dx-1;
if(mapp[dx][dy]=='.'&&dx<=n&&dx>=1&&dy>=1&&dy<=m)
{
x=dx;y=dy;
if(!vis[x][y])
ans++;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
cout<<ans<<endl;
sweep(n,m);
}
return 0;
}
rt。
赛时我过了最后一个样例 但是回家写的这个没有过
求各位大佬帮看看
by cjy0329 @ 2024-10-26 19:14:37
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
string mapp[1005];
int vis[1005][1005];
void sweep(int m,int n)
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
vis[i][j]=0;
}
}
signed main()
{
cin>>t;
while(t--)
{
int ans=1;
int n,m,k;
cin>>n>>m>>k;
int x,y,d;
cin>>x>>y>>d;
vis[x][y]=1;
for(int i=1;i<=n;i++)
{
cin>>mapp[i];
mapp[i]='W'+mapp[i];
}
while(k--)
{
int dx=x,dy=y;
if(d==0)dy=dy+1;
if(d==1)dx=dx+1;
if(d==2)dy=dy-1;
if(d==3)dx=dx-1;
if(mapp[dx][dy]=='.'&&dx<=n&&dx>=1&&dy>=1&&dy<=m)
{
x=dx;y=dy;
if(!vis[x][y])
ans++;
vis[x][y]=1;
}
else{
d=(d+1)%4;
}
}
cout<<ans<<endl;
sweep(n,m);
}
return 0;
}
添加一行
vis[x][y]=1;
第一格要标记
by Eva_91418 @ 2024-10-26 19:16:38
@cjy0329 啊啊啊啊啊啊谢谢大佬!!!就是这句!!!