• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            oyjpArt ACM/ICPC算法程序設(shè)計(jì)空間

            // I am new in programming, welcome to my blog
            I am oyjpart(alpc12, 四城)
            posts - 224, comments - 694, trackbacks - 0, articles - 6

            PKU1925 Spiderman 【DP】

            Posted on 2007-04-05 20:41 oyjpart 閱讀(2325) 評(píng)論(2)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

            Spiderman
            Time Limit:5000MS  Memory Limit:65536K
            Total Submit:1762 Accepted:197

            Description
            Dr. Octopus kidnapped Spiderman's girlfriend M.J. and kept her in the West Tower. Now the hero, Spiderman, has to reach the tower as soon as he can to rescue her, using his own weapon, the web.

            From Spiderman's apartment, where he starts, to the tower there is a straight road. Alongside of the road stand many tall buildings, which are definitely taller or equal to his apartment. Spiderman can shoot his web to the top of any building between the tower and himself (including the tower), and then swing to the other side of the building. At the moment he finishes the swing, he can shoot his web to another building and make another swing until he gets to the west tower. Figure-1 shows how Spiderman gets to the tower from the top of his apartment – he swings from A to B, from B to C, and from C to the tower. All the buildings (including the tower) are treated as straight lines, and during his swings he can't hit the ground, which means the length of the web is shorter or equal to the height of the building. Notice that during Spiderman's swings, he can never go backwards.


            You may assume that each swing takes a unit of time. As in Figure-1, Spiderman used 3 swings to reach the tower, and you can easily find out that there is no better way.

             

            Input
            The first line of the input contains the number of test cases K (1 <= K <= 20). Each case starts with a line containing a single integer N (2 <= N <= 5000), the number of buildings (including the apartment and the tower). N lines follow and each line contains two integers Xi, Yi, (0 <= Xi, Yi <= 1000000) the position and height of the building. The first building is always the apartment and the last one is always the tower. The input is sorted by Xi value in ascending order and no two buildings have the same X value.

            Output
            For each test case, output one line containing the minimum number of swings (if it's possible to reach the tower) or -1 if Spiderman can't reach the tower.

            Sample Input

            2
            6
            0 3
            3 5
            4 3
            5 5
            7 4
            10 4
            3
            0 3
            3 4
            10 4
            

             

            Sample Output

            3
            -1
            

             

            Source
            Beijing 2004 Preliminary@POJ

            這是DP題,根據(jù)坐標(biāo)DP是比較好的選擇,提交中wa多次。經(jīng)回復(fù)指點(diǎn) 才注意到建筑物高度相乘越界了 謝謝提醒了

            //Solution by oyjpArt
            #include <stdio.h>
            #include <math.h>
            #include <string.h>
            const int N = 5010;
            const int M = 1000010;
            int x[N], y[N], dp[M], nb;
            const int MAXINT = 2000000000;
            #define Min(a,b) ((a) < (b) ? (a) : (b))

            int main() {
             int ntc, i, j;
             scanf("%d", &ntc);
             while(ntc--) {
              scanf("%d", &nb);
              for(i = 0; i<nb; i++)  scanf("%d %d", x+i, y+i);
              int m = x[nb-1];
              memset(dp, -1, (m+1)*sizeof(dp[0]));
              dp[x[0]] = 0;
              double h = y[0]; 
              for(i = 1; i<nb; i++) { //以1..i的建筑為中介進(jìn)行飛行
               int d = sqrt(2*y[i]*h - h*h); //不會(huì)墜落到地上的最長距離 sqrt(y[i]*y[i]-sqare(y[i]-h))
               for(j = 1; j<=d; j++) { //DP
                if(x[i]-j < x[0]) break; //無用狀態(tài)
                if(dp[x[i]-j] == -1) continue; //不可達(dá)
                int k = x[i]+j < m ? x[i]+j : m;
                if(dp[k] == -1) dp[k] = dp[x[i]-j]+1;
                else dp[k] = Min(dp[k], dp[x[i]-j]+1);
               }//for
              }//for
              printf("%d\n", dp[m]);
             }
             return 0;
            }

            Feedback

            # re: PKU1925 Spiderman 【DP】  回復(fù)  更多評(píng)論   

            2007-04-11 15:24 by mark
            int的話相乘后可能越界了

            # re: PKU1925 Spiderman 【DP】  回復(fù)  更多評(píng)論   

            2007-04-16 20:53 by oyjpart
            謝謝提醒 呵呵
            久久久噜噜噜久久| 国产一区二区精品久久凹凸| 欧美伊人久久大香线蕉综合| 久久精品人人做人人爽电影| 久久精品www人人爽人人| 色偷偷888欧美精品久久久| 日韩电影久久久被窝网| 久久精品国产亚洲AV无码娇色 | 精品无码久久久久久国产| 亚洲国产成人久久一区久久| 人妻丰满AV无码久久不卡| 国产高潮国产高潮久久久91| 中文字幕无码久久精品青草| 国产精品久久久久…| 国产亚洲美女精品久久久2020| 亚洲综合婷婷久久| 久久一日本道色综合久久| 久久只这里是精品66| 9191精品国产免费久久| 久久精品国产亚洲av影院| 成人综合久久精品色婷婷| 久久九九久精品国产| 国产成人综合久久综合| 中文国产成人精品久久不卡| 欧美亚洲另类久久综合婷婷| 国产精品嫩草影院久久| 久久精品国产亚洲麻豆| 久久精品欧美日韩精品| 久久精品人人做人人妻人人玩| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 久久婷婷国产剧情内射白浆| 国产精品久久久久久久午夜片| 久久99国产综合精品| 久久无码高潮喷水| 久久亚洲中文字幕精品一区四| 99久久婷婷国产综合精品草原| 久久久无码人妻精品无码| 人妻久久久一区二区三区| 蜜臀av性久久久久蜜臀aⅴ | 国产99久久久国产精免费| 欧美伊香蕉久久综合类网站|