40pts求调

P11228 [CSP-J 2024] 地图探险

shx2011 @ 2024-10-27 20:46:16

连样例都过不了qwq

#include<bits/stdc++.h>
using namespace std;
int T;
char a[1010][1010];
bool vis[1010][1010];
int n,m,k,x,y,d;
int main(){
    cin>>T;
    while(T--){
        cin>>n>>m>>k;
        cin>>x>>y>>d;
        int ans=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>a[i][j];
                vis[i][j]=0;
            }
        } 

        for(int i=1;i<=k;i++){

            //cout<<"("<<d<<","<<x<<","<<y<<","<<i<<","<<ans<<")"<<"->";
            //cout<<"("<<x<<","<<y<<") ";
            if(d==0 && a[x][y+1]=='.' && !vis[x][y+1]){
                y+=1;
                ans+=1;
                //cout<<"Move:";
                continue;
            }else if(d==1 && a[x+1][y]=='.' && !vis[x+1][y]){
                x+=1;
                ans+=1;
                //cout<<"Move:";
                continue; 
            }else if(d==2 && a[x][y-1]=='.' && !vis[x][y-1]){
                y-=1;
                ans+=1; 
                //cout<<"Move:";
                continue;
            }else if(d==3 && a[x-1][y]=='.' && !vis[x-1][y]){
                x-=1;
                ans+=1;
                //cout<<"Move:";
                continue;
            }else{
                d=(d+1)%4;
                continue;
            }

            //if(i==k) ans++;
        }

        cout<<ans<<endl;
    }
    return 0;
}

by caijunhan2012 @ 2024-10-27 21:01:15

这是我的代码,你试一下

#include<bits/stdc++.h>
using namespace std;
int t,n,m,k,x,y,d,dt[1008][1008],sum=1;
string s[1008];
int main(){
    for(int i=0;i<1003;i++){
        dt[i][0]=1;
        dt[0][i]=1;
    }
    cin>>t;
    for(int u=0;u<t;u++){
        sum=1;
        cin>>n>>m>>k>>x>>y>>d;
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(s[i-1][j-1]=='x'){
                    dt[i][j]=1;
                }
                else{
                    dt[i][j]=0;
                }
            }
        }
        for(int i=0;i<=n;i++){
            dt[i][m+1]=1;
        }
        for(int i=0;i<=m;i++){
            dt[n+1][i]=1;
        }
        dt[x][y]=2;
        for(int i=0;i<k;i++){
            if(d==0){
                if(dt[x][y+1]!=1){
                    ++y;
                }
                else{
                    d=(d+1)%4;
                }
            }
            else if(d==1){
                if(dt[x+1][y]!=1){
                    ++x;
                }
                else{
                    d=(d+1)%4;
                }
            }
            else if(d==2){
                if(dt[x][y-1]!=1){
                    --y;
                }
                else{
                    d=(d+1)%4;
                }
            }
            else{
                if(dt[x-1][y]!=1){
                    --x;
                }
                else{
                    d=(d+1)%4;
                }
            }
            if(dt[x][y]!=2){
                sum++;
            }
            dt[x][y]=2;
        }
        cout<<sum<<endl;
    }
    return 0;
}

by MaCity @ 2024-10-27 21:09:57

@shx2011 看一下我的吧,我感觉都好像比较长

#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int t;
int n,m,k;
int x,y,c; 
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
char a[N][N];
bool vis[N][N];
int ans;
int main(){
    cin >> t;
    while(t--){
        ans=1;
        memset(vis,0,sizeof(vis));
        cin >> n >> m >> k;
        cin >> x >> y >> c;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                cin >> a[i][j];
            }
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++){
                cout<<a[i][j];
            }
            cout<<endl;
        }
        vis[x][y]=1;
        while(k--){
            if(x+dx[c]<1||x+dx[c]>n||y+dy[c]<1||y+dy[c]>m||a[x+dx[c]][y+dy[c]]=='x'){
                c=(c+1)%4;
            }else{
                x+=dx[c];
                y+=dy[c];
                if(vis[x][y]!=1){
                    ans++;   
                    vis[x][y]=1;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

by LANDER_TT @ 2024-10-27 21:13:06

#include<bits/stdc++.h>
using namespace std;
int T,v[1010][1010];
char a[1010][1010];
bool vis[1010][1010];
int n, m, k, x, y, d;
int main() {
    cin >> T;
    while (T--) {
        cin >> n >> m >> k;
        cin >> x >> y >> d;
        int ans = 0;
        for(int i=1;i<=1005;++i)            //初始化
            for(int j=1;j<=1005;++j)
                a[i][j]=' ',vis[i][j]=0,v[i][j]=0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> a[i][j];
                vis[i][j] = 1;    //标记用错了
            }
        }
        for (int i = 1; i <= k; i++) {
            if(v[x][y]==0){
                ans ++;
                v[x][y]=1;
            }
            if (d == 0 && a[x][y + 1] == '.' && vis[x][y + 1]) {
                y += 1;
                continue;
            } 
            else if (d == 1 && a[x + 1][y] == '.' && vis[x + 1][y]) {
                x += 1;
                continue;
            } 
            else if (d == 2 && a[x][y - 1] == '.' && vis[x][y - 1]) {
                y -= 1;
                continue;
            } 
            else if (d == 3 && a[x - 1][y] == '.' && vis[x - 1][y]) {
                x -= 1;
                continue;
            } 
            else {
                d = (d + 1) % 4;
                continue;
            }
        }
        if(v[x][y]==0){             //需要判断最后是否走到新的格点
            ans ++;
            v[x][y]=1;
        }
        cout << ans << endl;
    }
    return 0;
}
//BY: xjcw2022J
//LANDER_TT        关这个
//a_silver_star939   注:这个b没实名所以关不了
//求关

@ shx2011


by LANDER_TT @ 2024-10-27 21:13:58

@shx2011

调出来了,问题已注明

求关


by shx2011 @ 2024-10-27 21:39:17

@LANDER_TT 已关,谢谢


|