70pts求调

P11228 [CSP-J 2024] 地图探险

1zhangziheng2023 @ 2024-10-29 19:15:09

code:

#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,k;
int x,y,d;
char a[1005][1005];
bool v[1005][1005];
int main(){
    cin>>T;
    while(T--){
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
                v[i][j]=0;
            }
        }
        int s=1;
        v[x][y]=1;
        while(k--){
            if(d==0){
                if(a[x][y+1]=='.'){
                    y++;
                    if(v[x][y]==0){
                        v[x][y]=1;
                        s++;
                    }
                }
                else d=(d+1)%4;
            }
            else if(d==1){
                if(a[x+1][y]=='.'){
                    x++;
                    if(v[x][y]==0){
                        v[x][y]=1;
                        s++;
                    }
                }
                else d=(d+1)%4;
            }
            else if(d==2){
                if(a[x][y-1]=='.'){
                    y--;
                    if(v[x][y]==0){
                        v[x][y]=1;
                        s++;
                    }
                }
                else d=(d+1)%4;
            }
            else if(d==3){
                if(a[x-1][y]=='.'){
                    x--;
                    if(v[x][y]==0){
                        v[x][y]=1;
                        s++;
                    }
                }
                else d=(d+1)%4;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}

by nnbnwd @ 2024-10-29 21:43:48

我也70和你一样的思路


#include<bits/stdc++.h>
using namespace std;
int n;
char map1[1006][1006];
int vis[1006][1006]={},jl;
int zx,zy,sp,xx,xy,fx;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int cnt=0;
        cin>>zx>>zy>>sp;
        cin>>xx>>xy>>fx;
        for(int j=1;j<=zx;j++){
            for(int k=1;k<=zy;k++){
                cin>>map1[j][k];
            }
        }
        vis[xx][xy]=1;
        for(int j=1;j<=sp;j++){
            if(fx==0){
                if(map1[xx][xy+1]=='.'){
                    vis[xx][xy+1]=1;
                    xy+=1;
                    continue;
                }
                else if(map1[xx][xy+1]=='x'){
                    fx=(fx+1)%4;
                    continue;
                }
                else{
                    fx=(fx+1)%4;
                    continue;
                }
            }
            if(fx==1){
                if(map1[xx+1][xy]=='.'){
                    vis[xx+1][xy]=1;
                    xx+=1;
                    continue;
                }
                else if(map1[xx+1][xy]=='x'){
                    fx=(fx+1)%4;
                    continue;
                }
                else{
                    fx=(fx+1)%4;
                    continue;
                }
            }
            if(fx==2){
                if(map1[xx][xy-1]=='.'){
                    vis[xx][xy-1]=1;
                    xy-=1;
                    continue;
                }
                else if(map1[xx][xy-1]=='x'){
                    fx=(fx+1)%4;
                    continue;
                }
                else{
                    fx=(fx+1)%4;
                    continue;
                }
            }
            if(fx==3){
                if(map1[xx-1][xy]=='.'){
                    vis[xx-1][xy]=1;
                    xx-=1;
                    continue;
                }
                else if(map1[xx-1][xy]=='x'){
                    fx=(fx+1)%4;
                    continue;
                }
                else{
                    fx=(fx+1)%4;
                    continue;
                }
            }
        }
        for(int j=1;j<=zx;j++){
            for(int k=1;k<=zy;k++){
                if(vis[j][k]==1){
                    cnt++;
                    vis[j][k]=0;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

by nnbnwd @ 2024-10-29 21:45:28

@1zhangziheng2023

应该都是忘记判定边界了


by nnbnwd @ 2024-10-29 22:02:31

痛失70分


x > 0 && x <= n && y + 1 > 0 && y + 1 <= m

x + 1 <= n && x + 1 > 0 && y <= m && y > 0

x <= n && x > 0 && y - 1 <= m && y - 1 > 0

x - 1 <= n && x - 1 > 0 && y <= m && y > 0
//以上代码都该死

by nnbnwd @ 2024-10-29 22:03:19

说错了是痛失30分


by 1zhangziheng2023 @ 2024-10-30 10:14:57

@nnbnwd 已AC,thx 默哀


|