60分求调

P11228 [CSP-J 2024] 地图探险

Li_Wenshuo @ 2024-11-05 19:00:54

#include<bits/stdc++.h>
using namespace std;
char a[1010][1010];bool s[1010][1010];
int b[10]={0,1,1,0,0,-1,-1,0};
int main(){
    freopen("explore.in","r",stdin);
    freopen("explore.out","w",stdout);
    int n,t,k,m,num,x,y,d,xn,xnn,ynn;
    cin>>t;
    for(int i=1;i<=t;i++){
        num=1;
        scanf("%d%d%d%d%d%d",&n,&m,&k,&x,&y,&d);
        s[x][y]=1;
        for(int z=1;z<=n;z++)
            for(int j=1;j<=m;j++)
                cin>>a[z][j];
        for(int z=1;z<=k;z++){
            xn=d*2;
            xnn=x+b[xn];
            ynn=y+b[xn+1];
            if(a[xnn][ynn]=='.'){
                x+=b[xn];
                y+=b[xn+1];
                if(!s[x][y]){
                    num++;s[x][y]=1;
                }                   
                continue;
            }
            else{
                d=(d+1)%4;
            }
        }
        cout<<num<<"\n";
        if(i==t) return 0;
        for(int z=1;z<=n;z++)
            for(int j=1;j<=m;j++)
                s[z][j]=0;
    }
    return 0;
}

by Lyx8058 @ 2024-11-05 21:31:13

@Li_Wenshuo 死因:没判断边界

#include<bits/stdc++.h>
using namespace std;
char a[1010][1010];bool s[1010][1010];
int b[10]={0,1,1,0,0,-1,-1,0};
int main(){
    int n,t,k,m,num,x,y,d,xn,xnn,ynn;
    cin>>t;
    for(int i=1;i<=t;i++){
        num=1;
        scanf("%d%d%d%d%d%d",&n,&m,&k,&x,&y,&d);
        s[x][y]=1;
        for(int z=1;z<=n;z++)
            for(int j=1;j<=m;j++)
                cin>>a[z][j];
        for(int z=1;z<=k;z++){
            xn=d*2;
            xnn=x+b[xn];
            ynn=y+b[xn+1];
            if(a[xnn][ynn]=='.'&&ynn>=1&&ynn<=m&&xnn>=1&&xnn<=n){
                x+=b[xn];
                y+=b[xn+1];
                if(!s[x][y]){
                    num++;s[x][y]=1;
                }                   
                continue;
            }
            else{
                d=(d+1)%4;
            }
        }
        cout<<num<<"\n";
        if(i==t) return 0;
        for(int z=1;z<=n;z++)
            for(int j=1;j<=m;j++)
                s[z][j]=0;
    }
    return 0;
}

by Timing703 @ 2024-11-05 21:35:37

@Lyx8058 @Lyx8058 我累个巨佬啊


by Lyx8058 @ 2024-11-05 21:40:25

@zhangkaizhi 好孤独,同学有几个好朋友退役了。


by Timing703 @ 2024-11-05 22:02:54

@Lyx8058 可怜巨佬 所以还的我们小学生好,嘻嘻


by Timing703 @ 2024-11-05 22:04:40

@Lyx8058 虽然我这次第二题写挂了 只拿了100分,我朋友说我是飞舞


by zhangjingbo @ 2024-12-20 21:16:53

@Timing703本来就飞舞


|