第二和第十个一直显示RE

P1434 [SHOI2002] 滑雪

Siing_Rousong @ 2021-04-20 19:27:01

题解里也有与我十分相似的代码

#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int place[105][105] = {0};
int record[105][105] = {0};
int ans = 0;
int flag = 1;
int max_e = 0;

struct point {
    int x;
    int y;
    int height;
};
point point_record[105];

bool cmp(point a, point b) {
    return a.height < b.height;
}

void findpathlength(int r, int c) {
    for (int i = 1; i <= r * c; i++) {
        int up=0, down=0, left=0, right=0;
        int now_x = point_record[i].x;
        int now_y = point_record[i].y;
        int now_height = point_record[i].height;

                if (place[now_x - 1][now_y] < now_height) {
                    up = record[now_x - 1][now_y];
                }
                record[now_x][now_y] = max(up+1, record[now_x][now_y]);

                if (place[now_x + 1][now_y] < now_height) {
                    down = record[now_x+ 1][now_y];
                }
                record[now_x][now_y] = max(down + 1, record[now_x][now_y]);

                if (place[now_x][now_y-1] < now_height) {
                    left = record[now_x][now_y-1];
                }
                record[now_x][now_y] = max(left + 1, record[now_x][now_y]);

                if (place[now_x][now_y +1] < now_height) {
                    right = record[now_x][now_y+1];
                }
                record[now_x][now_y] = max(right + 1, record[now_x][now_y]);

                if (max_e < record[now_x][now_y])max_e = record[now_x][now_y];  
            }
}

int main()
{
    int row, col;
    cin >> row >> col;
    for (int i = 1; i <= row; i++) {
        for (int j = 1; j <= col; j++)
        {
            cin >> place[i][j];
            point_record[flag].x = i;
            point_record[flag].y = j;
            point_record[flag].height = place[i][j];
            record[i][j] = 1;
            flag++;
        }
    }
    sort(point_record+1 , point_record + row * col+1 ,cmp);
    findpathlength(row,col);
    cout << max_e;
}

by Hooch @ 2021-05-05 21:04:18

point数组要开100 * 100

point point_record[105];

by rwchen @ 2021-05-09 15:56:15

@D_K_D 感谢老哥,我说我半天老答案错误,我也是point数组开小了,应该开point[100*100]我给开成了point[100]哈哈哈,大意了


|