10pts 求条

P11228 [CSP-J 2024] 地图探险

liyishao1125 @ 2024-10-28 19:30:37

#include<bits/stdc++.h>
using namespace std;
int t,n,m,k;
char a[1145][1145];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--){
        int cnt=0;
        cin>>n>>m>>k;
        int x,y,d;
        cin>>x>>y>>d;
        bool ans[1145][1145];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        ans[x][y]=1;
        for(int i=1;i<=k;i++){
            if(d==0){
                ans[x][y+1]=1;
                if(a[x][y+1]=='x'||x<1||x>n||y+1<1||y+1>m){
                    ans[x][y+1]=0;
                    d=(d+1)%4;
                    continue;
                }
                y++;
            }
            if(d==1){
                ans[x+1][y]=1;
                if(a[x+1][y]=='x'||x+1<1||x+1>n||y<1||y>m){
                    ans[x+1][y]=0;
                    d=(d+1)%4;
                    continue;
                }
                x++;
            }
            if(d==2){
                ans[x][y-1]=1;
                if(a[x][y-1]=='x'||x<1||x>n||y-1<1||y-1>m){
                    ans[x][y-1]=0;
                    d=(d+1)%4;
                    continue;
                }
                y--;        
            }
            if(d==3){
                ans[x-1][y]=1;
                if(a[x-1][y]=='x'||x-1<1||x-1>n||y<1||y>m){
                    ans[x-1][y]=0;
                    d=(d+1)%4;
                    continue;
                }
                x--;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(ans[i][j]){
                    cnt++;
                }
            }
        }
        cout<<cnt<<"\n";
    }
}

只A了#5


by liyishao1125 @ 2024-10-28 19:49:07

已AC 多测未清空


by liyishao1125 @ 2024-10-28 19:49:24

此贴结


|