NEGATUIVE_SEVEN_DL @ 2024-11-04 22:41:11
#include<bits/stdc++.h>
using namespace std;
int T;
long long n,m,k,x,y,d,cnt;
int book[10005][10005];
char mapn[10005][10005];
int main()
{
// freopen("explore.in","r",stdin);
// freopen("explore.out","w",stdout);
cin>>T;
while(T--)
{
cnt=0;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
book[i][j]=0;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>mapn[i][j];
}
}
for(int i=1;i<=k;i++)
{
int x_1=x,y_1=y;
if(d==0) y_1=y_1+1;
else if(d==1) x_1=x_1+1;
else if(d==2) y_1=y_1-1;
else if(d==3) x_1=x_1-1;
if((x<=n&&y<=m)&&(mapn[x_1][y_1]=='.'))
{
x=x_1;
y=y_1;
book[x][y]=1;
}
else d=(d+1)%4;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(book[i][j]==1)
{
cnt++;
}
}
}
cout<<cnt+1<<endl;
}
return 0;
}
by NEGATUIVE_SEVEN_DL @ 2024-11-04 22:41:54
样例1是对的。?
by yangyuhan_yyh @ 2024-11-08 20:38:55
@xxxxx_ 对的
by yangyuhan_yyh @ 2024-11-08 20:39:29
#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,y,d,b[1001][1001];
char a[1001][1001];
int main(){
int t;cin>>t;
for(int q=1;q<=t;q++){
long long sum=0,ans=0;
cin>>n>>m>>k>>x>>y>>d;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];b[i][j]=0;
if(a[i][j]=='.')ans++;
}
}b[x][y]=1;
while(k>0&&ans>0){
while((k>0)&&((d==0&&a[x][y+1]=='x')||(d==1&&a[x+1][y]=='x')||(d==2&&a[x][y-1]=='x')||(d==3&&a[x-1][y]=='x')||(d==0&&y+1>m)||(d==1&&x+1>n)||(d==2&&y-1<=0)||(d==3&&x-1<=0))){
d=(d+1)%4,k--;
}if(d==0)y++;
else if(d==1)x++;
else if(d==2)y--;
else if(d==3)x--;
k--;if(k>=0){
b[x][y]++;
if(b[x][y]==1)ans--;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(b[i][j]!=0)sum++;
}
}cout<<sum<<endl;
}
return 0;
}