70pts求条

P11228 [CSP-J 2024] 地图探险

To_2051 @ 2024-10-27 16:17:10

rt,WA on #7 #8 #10

#include<bits/stdc++.h>
using namespace std;
int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
char c[1001][1001];bool v[1001][1001];
int main()
{
    freopen("1.in","r",stdin);
int t;
cin>>t;
while(t--)
{
    int n,m,k,d,x,y,xx,yy;
    cin>>n>>m>>k;
    cin>>x>>y>>d;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            c[i][j]='x',v[i][j]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>c[i][j];
        }
    }
    for(int i=1;i<=k+1;i++)
    {
        v[x][y]=1;
//      cout<<"x="<<x<<" y="<<y<<" d="<<d<<"\n";
//      cout<<"x+="<<dir[d][0]<<" y+="<<dir[d][1]<<endl;
        int xx=x+dir[d][0],yy=y+dir[d][1];
        if(c[xx][yy]=='.') 
        {
            x=xx,y=yy;
        }
        else 
        {
            d=(d+1)%4;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(v[i][j]) ans++;
        }
    }
    cout<<ans<<endl;
}
    return 0;
}

by To_2051 @ 2024-10-27 16:21:31

破案了,未判边界


by To_2051 @ 2024-10-27 16:21:41

此贴结


by tanzili @ 2024-10-27 16:24:11

在循环开头加个memset(c,0,sizeof(c)),可以不判边界


|