• poj1088 滑雪


    题目链接:http://poj.org/problem?id=1088

    题目大意:输入一个二维数组a[i][j], a[i][j] 的值代表所在高度, 滑雪要从高处滑到低处,上下左右四个方向, 问最大能经过几个阶段?

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <cstdio>
     5 #include <algorithm>
     6 #include <vector>
     7 #include <map>
     8 using namespace std;
     9 
    10 int to[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    11 struct node
    12 {
    13     int x, y, val;
    14 }rc[10020];
    15 int cmp(node a, node b)
    16 {
    17     return a.val < b.val;
    18 }
    19 int main()
    20 {
    21     int r, c, i, j, h[120][120], len[120][120];
    22     scanf("%d %d", &r, &c);
    23     int t = -1;
    24     memset(len, 0, sizeof(len));
    25     for(i = 0; i < r; i++)
    26     {
    27         for(j = 0; j < c; j++)
    28         {
    29             scanf("%d", &h[i][j]);
    30             t++;
    31             rc[t].x = i, rc[t].y = j;
    32             rc[t].val = h[i][j];
    33         }
    34     }
    35     sort(rc, rc + r * c, cmp);
    36     for(i = 0; i < r * c; i++)
    37     {
    38         int x = rc[i].x;
    39         int y = rc[i].y;
    40         for(j = 0; j < 4; j++)
    41         {            
    42             int tx = x + to[j][0];
    43             int ty = y + to[j][1];
    44             if(tx >= 0 && tx < r && ty >= 0 && ty < c)
    45             {
    46                 if(h[x][y] < h[tx][ty] && len[x][y] >= len[tx][ty])
    47                     len[tx][ty] = len[x][y] + 1;
    48             }            
    49         }        
    50     }
    51     int max = 0;
    52     for(i = 0; i < r; i++)
    53     {
    54         for(j = 0; j < c; j++)
    55         {
    56            // cout << len[i][j] << " ";
    57             if(len[i][j] > max)
    58                 max = len[i][j];
    59         }
    60     }
    61     printf("%d
    ", max + 1);
    62     return 0;
    63 }
  • 相关阅读:
    肥胖儿筛选标准
    文章索引
    面向对象66原则
    [精]Xpath路径表达式
    [精]XPath入门教程
    孕产期高危因素
    “华而不实”的转盘菜单(pie menu)
    xmind用例导excel用例,然后再用python排版
    NSObject
    [self class]与[super class]
  • 原文地址:https://www.cnblogs.com/luomi/p/5433130.html
Copyright © 2020-2023  润新知