posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          PKU 1008 滑雪

          Posted on 2007-05-19 22:19 ZelluX 閱讀(378) 評(píng)論(0)  編輯  收藏 所屬分類: Algorithm

          5.19
          第一反應(yīng)覺得是個(gè)簡單的BFS,從最高點(diǎn)開始向四周擴(kuò)展,最后找到最長的路徑即可。
          結(jié)果Wrong Answer,仔細(xì)一想,才意識(shí)到并不一定是從最高點(diǎn)開始的。考慮得太不周到了。。

          5.31
          原來的程序找不到了。。。重新寫了一遍,居然寫好提交就AC了,恩。這幾天進(jìn)步挺大哈

          #include <iostream>
          #include 
          <fstream>
          #include 
          <algorithm>
          #include 
          <vector>

          using namespace std;

          const int MAX_HEIGHT = 10000;
          const int MAX_ROWS = 100;
          const int dx[] = {00-11};
          const int dy[] = {1-100};

          struct Point {
              
          int x;
              
          int y;
              
          int height;
          }
          ;

          bool comparePoints(const Point& p1, const Point& p2);
          int main() {
              
          //ifstream fin("pku1088.in");
              int c, r;
              
          int i, j;
              cin 
          >> r >> c;
              
          int h[MAX_ROWS + 2][MAX_ROWS + 2];
              
          int count = 0;
              vector
          <Point> points;
              
          for (i = 1; i <= r; i++{
                  
          for (j = 1; j <= c; j++{
                      cin 
          >> h[i][j];
                      Point temp;
                      temp.x 
          = i;
                      temp.y 
          = j;
                      temp.height 
          = h[i][j];
                      points.push_back(temp);
                  }

              }


              sort(points.begin(), points.end(), comparePoints);
              
              
          for (i = 0; i <= c; i++{
                  h[
          0][i] = MAX_HEIGHT + 1;
                  h[r 
          + 1][i] = MAX_HEIGHT + 1;
              }

              
          for (i = 0; i <= r; i++{
                  h[i][
          0= MAX_HEIGHT + 1;
                  h[i][c 
          + 1= MAX_HEIGHT + 1;
              }


              
          int f[MAX_ROWS + 1][MAX_ROWS + 1];
              
          for (i = 1; i <= r; i++{
                  
          for (int j = 1; j <= c; j++{
                      f[i][j] 
          = 1;
                  }

              }

              
              vector
          <Point>::iterator iter;
              
          for (iter = points.begin(); iter != points.end(); iter++{
                  
          for (i = 0; i < 4; i++{
                      
          int nx = iter->+ dx[i];
                      
          int ny = iter->+ dy[i];
                      
          if (iter->height > h[nx][ny]) {
                          
          if (f[iter->x][iter->y] + 1 > f[nx][ny]) {
                              f[nx][ny] 
          = f[iter->x][iter->y] + 1;
                          }

                      }

                  }

              }


              
          int best = 0;
              
          for (i = 1; i <= r; i++{
                  
          for (j = 1; j <= c; j++{
                      
          if (f[i][j] > best) {
                          best 
          = f[i][j];
                      }

                  }

              }

              cout 
          << best << endl;
              
          return 0;
          }


          bool comparePoints(const Point& p1, const Point& p2) {
              
          return (p1.height > p2.height);
          }
          主站蜘蛛池模板: 六枝特区| 晋州市| 湛江市| 阳高县| 梅河口市| 逊克县| 星子县| 温州市| 乌什县| 星座| 丘北县| 义乌市| 互助| 日照市| 句容市| 镇坪县| 北海市| 通化县| 甘洛县| 蒙城县| 西贡区| 敖汉旗| 岳池县| 新绛县| 雅安市| 呼图壁县| 山阴县| 株洲市| 绥德县| 五台县| 永新县| 平昌县| 凤庆县| 营山县| 南宁市| 三门峡市| 梁山县| 农安县| 三江| 北京市| 读书|