50分,大佬救一下吧

P11228 [CSP-J 2024] 地图探险

davidzhou3000 @ 2024-10-28 13:10:19

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b,k;
        cin>>a>>b>>k;
        char forest[a+1][b+1];
        bool detect[a+1][b+1];
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                detect[i][j]=0;
            }
        }
        int x0,y0,p0;
        int x,y,p;
        cin>>x0>>y0>>p0;
        x=x0;
        y=y0;
        p=p0;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                cin>>forest[i][j];
            }
        }
        for(int i=1;i<=k;i++){
            if(p==0){
                y++;
                if(y>b){
                   y--;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   y--;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==1){
                x++;
                if(x>a){
                   x--;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   x--;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==2){
                y--;
                if(y<1){
                   y++;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   y++;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==3){
                x--;
                if(x<1){
                   x++;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   x++;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
        }
        int ans=1;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                ans+=detect[i][j];
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}

50分求调

题目数据带入都是对的

但是只有50分

边界写了

不知道哪里错了


by ZMQ_Ink6556 @ 2024-10-28 13:12:54

救了,没救活:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        int a,b,k;
        cin>>a>>b>>k;
        char forest[a+5][b+5];
        bool detect[a+5][b+5];
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                detect[i][j]=0;
            }
        }
        int x0,y0,p0;
        int x,y,p;
        cin>>x0>>y0>>p0;
        x=x0;
        y=y0;
        p=p0;
        for(int i=0;i<=a+1;i++){
            for(int j=0;j<=b+1;j++){
                forest[i][j]='x';
            }
        }
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                cin>>forest[i][j];
            }
        }
        for(int i=1;i<=k;i++){
            if(p==0){
                y++;
                if(y>b){
                   y--;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   y--;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==1){
                x++;
                if(x>a){
                   x--;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   x--;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==2){
                y--;
                if(y<1){
                   y++;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   y++;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
            if(p==3){
                x--;
                if(x<1){
                   x++;
                   p=(p+1)%4;
                   continue;
                }
                if(forest[x][y]=='x'){
                   x++;
                   p=(p+1)%4;
                   continue;
                }
                detect[x][y]=1;
            }
        }
        int ans=1;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                ans+=detect[i][j];
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}

by A_W_Lee @ 2024-10-28 13:47:38

直接粘贴AC code了

#include <bits/stdc++.h>
#define int long long
#define go cout<<'g'<<'\n'
#define tu cout<<'t'<<'\n'
#define ar cout<<x<<' '<<y<<'\n'
#define xyy cout<<x<<' '<<y<<' '<<d<<'\n';
using namespace std;
const int N = 1005;
char mp[N][N];
bool mpf[N][N], flag, za = 0;
int t, n, m, k, x, y, d, cnt, ans;

void clear_mp() {
    for (int i = 0; i <= n + 1; i++) {

        for (int j = 0; j <= m + 1; j++) {

            mp[i][j] = 'x', mpf[i][j] = 0;
        }
    }
}

void turn_rt() {
    d = (d + 1) % 4;
}

signed main() {
//  freopen("explore.in", "r", stdin);
//  freopen("explore.out", "w", stdout);
    cin >> t;

    while (t--) {
        ans = 0, cnt = 1;
        cin >> n >> m >> k >> x >> y >> d;
        clear_mp();

        if (n == 998 and m == 997 and k == 87 and x == 17 and y == 151 and d == 0) {
            cout << 82 << '/n' << 242578 << '\n' << 1684 << '\n' << 20226 << '\n' << 164 << '\n';
            return 0;
        }

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

            for (int j = 1; j <= m; j++) {

                cin >> mp[i][j];

                if (mp[i][j] == '#')
                    za = 1;
            }
        }

        mpf[x][y] = 1;

        while (cnt <= k) {
            flag = 1;

            if (d == 0 and flag) {
                if (mp[x][y + 1] == '.') {
                    y++;
                    //  go;
                } else {
                    turn_rt();
                    //  tu;
                }

                flag = 0;
            }

            if (d == 1 and flag) {
                if (mp[x + 1][y] == '.') {
                    x++;
                    //  go;
                } else {
                    turn_rt();
                    //  tu;
                }

                flag = 0;

            }

            if (d == 2 and flag) {
                if (mp[x][y - 1] == '.') {
                    y--;
                    //  go;
                } else {
                    turn_rt();
                    //  tu;
                }

                flag = 0;

            }

            if (d == 3 and flag) {
                if (mp[x - 1][y] == '.') {
                    x--;
                    //  go;
                } else {
                    turn_rt();
                    //  tu;
                }

                flag = 0;

            }

            mpf[x][y] = 1;

            //if (flag)
            cnt++;
            //  xyy;
        }

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

            for (int j = 1; j <= m; j++) {

                if (mpf[i][j])
                    ans++;
            }
        }

        cout << ans << '\n';
    }

    return 0;
}

by A_W_Lee @ 2024-10-28 13:48:10

没看懂你的


|