📄 pku1088.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int x, y;
int h;
}Po;
int cmp(const void *a, const void *b)
{
Po *c = (Po *)a;
Po *d = (Po *)b;
return c->h - d->h;
}
int main()
{
int h[101][101];
int t[101][101] = {1};
int R, C, i, j, x, y, n, max, k;
Po p[10001];
scanf("%d%d", &R, &C);
for (i = 0, k = 0; i < R; i++)
{
for (j = 0; j < C; j++)
{
scanf("%d", &h[i][j]);
t[i][j] = 1;
p[k].h = h[i][j];
p[k].x = j;
p[k].y = i;
k++;
}
}
qsort(p, R * C, sizeof(p[0]), cmp);
for (i = 0, max = 0; i < R * C; i++)
{
x = p[i].x;
y = p[i].y;
if (x - 1 >= 0)
{
if (h[y][x - 1] < h[y][x] && t[y][x-1] >= t[y][x])
{
t[y][x] = t[y][x-1] + 1;
}
}
if (x + 1 < C)
{
if (h[y][x + 1] < h[y][x] && t[y][x + 1] >= t[y][x])
{
t[y][x] = t[y][x + 1] + 1;
}
}
if (y + 1 < R)
{
if (h[y + 1][x] < h[y][x] && t[y + 1][x] >= t[y][x])
{
t[y][x] = t[y + 1][x] + 1;
}
}
if (y - 1 >= 0)
{
if (h[y - 1][x] < h[y][x] && t[y - 1][x] >= t[y][x])
{
t[y][x] = t[y - 1][x] + 1;
}
}
if (t[y][x] > max)
{
max = t[y][x];
}
// printf("i = %d\t max= %d\n", i, max);
}
printf("%d\n", max);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -