为啥50分啊啊啊!!!求助!

P11228 [CSP-J 2024] 地图探险

ljz_Math @ 2024-10-26 22:31:10

#include<iostream>
using namespace std;
int main() {
    int T;//数据组数
    int n, m, k;//行数,列数,执行次数
    int x0, y0, d0;//起始横坐标,起始纵坐标,起始朝向
    char c[10000][10000] = { '0' };
    cin >> T;
    int sum[10000];
    int key[10000][10000] = { 0 };
    for (int i = 1; i <= T; i++) {
        sum[i] = 1;
    }
    for (int s = 1; s <= T; s++) {

        cin >> n >> m >> k;
        cin >> x0 >> y0 >> d0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                key[i][j] = 0;
            }
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                cin >> c[i][j];//输入地图
            }
        }
        for (int i = 1; i <= n; i++) {
            c[i][0] = '0';
            c[i][m + 1] = '0';
        }
        for (int j = 1; j <= m; j++) {
            c[0][j] = '0';
            c[n + 1][j] = '0';
        }
        //cout << c[1][0];
        //cout << endl;
        //cout << d0;
        for (int i = 1; i <= k; i++) {
            if (d0 == 0) {
                if (c[x0][y0 + 1] == '0' || c[x0][y0 + 1] == 'x') {
                    d0 = (d0 + 1) % 4;
                    //cout << "q1" << endl;
                }
                else {
                    if (key[x0][y0+1] == 1) {
                        sum[s] = sum[s];
                    }
                    else {
                        sum[s]++;
                        key[x0][y0+1] = 1;
                        //cout << "R0"<<endl;
                    }
                    y0++;
                }
            }
            else if (d0 == 1) {
                if (c[x0 + 1][y0] == '0' || c[x0 + 1][y0] == 'x') {
                    d0 = (d0 + 1) % 4;
                    //cout << "q1" << endl;
                }
                else {
                    if (key[x0+1][y0] == 1) {
                        sum[s] = sum[s];
                    }
                    else {
                        sum[s]++;
                        key[x0+1][y0] = 1;
                        //cout << "R1" << endl;
                    }
                    x0++;
                }
            }
            else if (d0 == 2) {
                if (c[x0][y0 - 1] == '0' || c[x0][y0 - 1] == 'x') {
                    d0 = (d0 + 1) % 4;
                    //cout << "q1" << endl;
                    //cout << d0 << endl;
                }
                else {
                    if (key[x0][y0-1] == 1) {
                        sum[s] = sum[s];
                    }
                    else {
                        sum[s]++;
                        key[x0][y0-1] = 1;
                        //cout << "R2" << endl;
                    }
                    y0--;
                }
            }
            else if (d0 == 3) {
                if (c[x0 - 1][y0] == '0' || c[x0 - 1][y0] == 'x') {
                    d0 = (d0 + 1) % 4;
                    //cout << "q1" << endl;
                }
                else {
                    if (key[x0-1][y0] == 1) {
                        sum[s] = sum[s];
                    }
                    else {
                        sum[s]++;
                        key[x0-1][y0] = 1;
                        //cout << "R3" << endl;
                    }
                    x0--;
                }
            }
        }
    }
    for (int i = 1; i <= T; i++) {
        cout << sum[i] << endl;
    }
    return 0;
}

by dfefawefwefefef @ 2024-10-26 22:36:43

@ljz_Math 起点也要标记


by caizihan925 @ 2024-10-26 22:46:14

为什么要写这么长??? 来我教你

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int N = 1e3 + 10, dx[10][10] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int t, n, m, sum, k, o, p, d, mp[N][N];

char c[N][N];

int main() {
    //freopen("explore3.in", "r", stdin);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while(t--){
        cin >> n >> m >> k >> o >> p >> d;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                cin >> c[i][j];
                mp[i][j] = 0;//用来标记是否走过,记得清空
            }
        }
        mp[o][p] = 1;//标记初始位置
        for(int g = 1; g <= k; g++){
            int x = o + dx[d][0], y = p + dx[d][1];
            if(x < 1 || x > n || y < 1 || y > m || c[x][y] == 'x'){//非法情况转向
                d = (d + 1) % 4;
            }else{//合法按题意模拟
                o = x, p = y;
                if(mp[o][p] == 0){//没到过
                    sum++;
                    mp[o][p] = 1;
                }
            }
        }
        cout << sum + 1 << '\n';
        sum = 0;
    }
    return 0;
}
/*
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!
我是蒟蒻!!!!!!!

*/

|