0分求条

P11228 [CSP-J 2024] 地图探险

Zouzhuoxuan @ 2024-11-08 23:59:11

#include<bits/stdc++.h>
#define int long long
#define N 1005
using namespace std;
char a[N][N];
bool vis[N][N];
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        int n,m,k,x,y,d,i,j,cnt=0,dx,dy;
        cin>>n>>m>>k>>x>>y>>d;
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++) a[i][j]=getchar();
            getchar();
        }
        for(i=1;i<=k;i++)
        {
            vis[x][y]=1;
            dx=0,dy=0;
            if(d==0) dy++;
            else if(d==1) dx++;
            else if(d==2) dy--;
            else dx--;
            if(x+dx<=n&&y+dy<=m&&x+dx>0&&y+dy>0&&a[x+dx][y+dy]=='.') x+=dx,y+=dy;
            else d=(d+1)%4;
        }
        for(i=1;i<=n;i++) for(j=1;j<=m;j++) cnt+=vis[i][j];
        cout<<cnt<<endl;
    }
    return 0;
}

by Zouzhuoxuan @ 2024-11-09 00:02:14

后来结尾加了vis[x][y]=1,还是0


by lpsz2024wcs @ 2024-11-09 01:04:51

@Zouzhuoxuan
ios::sync_with_stdio(0) 关闭同步流会与 getchar 发生化学反应,所以用 cin 就好了


by Zouzhuoxuan @ 2024-11-10 21:50:27

@lpsz2024wcs 之前以为cin>>a[i][j];会吸换行符,现在可以了,thx


|