青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// 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 閱讀(2342) 評論(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題,根據坐標DP是比較好的選擇,提交中wa多次。經回復指點 才注意到建筑物高度相乘越界了 謝謝提醒了

//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的建筑為中介進行飛行
   int d = sqrt(2*y[i]*h - h*h); //不會墜落到地上的最長距離 sqrt(y[i]*y[i]-sqare(y[i]-h))
   for(j = 1; j<=d; j++) { //DP
    if(x[i]-j < x[0]) break; //無用狀態
    if(dp[x[i]-j] == -1) continue; //不可達
    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】  回復  更多評論   

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

# re: PKU1925 Spiderman 【DP】  回復  更多評論   

2007-04-16 20:53 by oyjpart
謝謝提醒 呵呵
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲福利在线看| 久久亚洲春色中文字幕| 久久人人爽人人爽爽久久| 国产精品毛片大码女人| 99riav1国产精品视频| 欧美va日韩va| 久久久91精品国产| 红桃视频欧美| 久久久久成人精品| 久久久综合网站| 国产在线一区二区三区四区| 91久久久久久| 欧美韩国在线| 欧美二区视频| 99在线|亚洲一区二区| 亚洲国产乱码最新视频| 免费亚洲电影| 夜色激情一区二区| 一本久久青青| 国产精品igao视频网网址不卡日韩| 亚洲福利久久| 亚洲欧洲综合另类| 欧美日韩成人一区二区| 夜夜嗨av一区二区三区免费区| 亚洲精品视频在线播放| 猛男gaygay欧美视频| 日韩视频专区| 亚洲私人黄色宅男| 国产一区二区三区在线免费观看 | 夜夜夜精品看看| 欧美日韩一区在线| 久久精品国产成人| 亚洲一二三四区| 国产自产女人91一区在线观看| 免费不卡在线观看| 欧美人与性动交cc0o| 亚洲欧美日韩国产| 欧美激情一区| 欧美日韩系列| 久久久久久午夜| 欧美劲爆第一页| 欧美一区二区视频观看视频| 狠狠色狠色综合曰曰| 亚洲黄网站在线观看| 国产精品裸体一区二区三区| 久久综合狠狠综合久久综合88| 欧美精品激情blacked18| 亚洲欧美在线高清| 久久午夜激情| 香港成人在线视频| 欧美精品一区二区久久婷婷| 亚洲欧美成人一区二区三区| 久久婷婷国产综合尤物精品| 亚洲欧美乱综合| 两个人的视频www国产精品| 亚洲欧美一区二区激情| 亚洲一区二区三区精品在线| **性色生活片久久毛片| 亚洲无毛电影| 日韩一级大片| 久久夜色精品国产噜噜av| 午夜在线观看欧美| 欧美美女bb生活片| 欧美国产亚洲另类动漫| 国产中文一区二区| 亚洲欧美日产图| 亚洲精品一区在线观看香蕉| 久久亚洲综合色一区二区三区| 亚洲欧美国产视频| 欧美午夜免费影院| 亚洲欧洲一区二区三区在线观看| 在线精品视频一区二区| 99精品国产在热久久下载| 亚洲国内高清视频| 久久精品国产精品亚洲综合| 性久久久久久久久| 欧美日韩一区在线| 亚洲精品一区在线观看香蕉| 亚洲青色在线| 久久亚洲综合色| 欧美波霸影院| 国产综合久久久久久| 欧美亚洲日本一区| 欧美一级片在线播放| 国产精品国产三级欧美二区| 99视频超级精品| 一区二区三区精品在线| 欧美日韩调教| 亚洲视频欧美在线| 性欧美长视频| 国产麻豆午夜三级精品| 欧美一级专区免费大片| 久久精品99国产精品| 国产精品午夜av在线| 亚洲性夜色噜噜噜7777| 久久国产精品99久久久久久老狼| 一区二区av在线| 欧美日韩伦理在线免费| 免费观看在线综合色| 欧美自拍丝袜亚洲| 激情久久久久久久| 欧美国产激情| 亚洲桃花岛网站| 久热国产精品视频| 日韩视频二区| 国产欧美午夜| 欧美福利在线| 欧美中文字幕在线观看| 亚洲高清视频中文字幕| 欧美在线电影| 亚洲精品国产精品乱码不99 | 欧美亚洲综合另类| 麻豆精品精华液| 亚洲一区网站| 亚洲精品视频中文字幕| 国产欧美精品一区二区三区介绍 | 午夜视频久久久| 91久久久久久久久久久久久| 欧美一区二区三区免费观看| 亚洲人线精品午夜| 国产视频欧美视频| 欧美日韩一区高清| 欧美寡妇偷汉性猛交| 久久精品国产一区二区电影| 一区二区三区**美女毛片| 亚洲国产成人精品女人久久久| 欧美一级视频一区二区| 在线视频欧美精品| 亚洲精品自在久久| 亚洲风情在线资源站| 国产日韩一区二区| 国产精品免费一区二区三区观看 | 先锋影音网一区二区| 一本久道综合久久精品| 亚洲国产女人aaa毛片在线| 久久亚洲精品一区二区| 久久久久高清| 欧美伊人久久久久久久久影院 | 亚洲欧美日韩国产精品| 日韩一级欧洲| 亚洲精品乱码久久久久久| 在线日韩欧美| 亚洲国产日韩欧美| 在线精品视频一区二区三四| 国产在线观看一区| 国产在线一区二区三区四区| 国产一区二区三区高清播放| 国产精品无码永久免费888| 国产精品美女一区二区在线观看| 欧美日韩一区精品| 欧美视频日韩视频| 国产精品久久久久aaaa| 国产精品国产福利国产秒拍| 欧美女同在线视频| 国产精品videossex久久发布| 欧美日韩另类一区| 国产精品亚洲综合天堂夜夜| 国产精品爱久久久久久久| 欧美日韩在线第一页| 欧美网站大全在线观看| 国产精品乱码妇女bbbb| 国产农村妇女毛片精品久久莱园子| 国产精品久久国产精品99gif| 国产美女精品视频| 狠狠v欧美v日韩v亚洲ⅴ| 亚洲大胆美女视频| 9久re热视频在线精品| 亚洲一区在线播放| 久久免费高清视频| 欧美国产日韩一区二区| 99精品国产高清一区二区| 亚洲欧美日韩精品一区二区 | 日韩视频一区二区三区| 亚洲一区精品视频| 久久久久久欧美| 欧美日韩成人在线| 国产欧美日韩在线视频| 永久免费毛片在线播放不卡| 99国内精品久久| 欧美呦呦网站| 亚洲第一黄色网| 亚洲一区二区黄色| 蜜桃视频一区| 国产精品日韩在线| 亚洲国产精品一区二区www| 亚洲一区二区三区777| 久久久五月天| 99国产精品自拍| 久久久国产一区二区三区| 欧美日韩免费视频| 国内精品久久久久影院薰衣草| 99亚洲伊人久久精品影院红桃| 久久国产精品99国产精| 亚洲乱码国产乱码精品精可以看| 香蕉成人伊视频在线观看| 欧美激情网友自拍| 国内精品免费在线观看| 亚洲永久免费观看| 亚洲大片在线观看| 久久九九国产|