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

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>
            韩日欧美一区| 亚洲福利电影| 亚洲欧美日本日韩| 日韩图片一区| 国产精品日日摸夜夜摸av| 亚洲欧美另类久久久精品2019| 日韩亚洲在线| 国产精品网红福利| 久久综合五月| 欧美精品一区二区高清在线观看| 亚洲一区二区三区国产| 亚洲天堂网在线观看| 国产原创一区二区| 欧美激情精品久久久久久蜜臀| 欧美理论在线| 欧美在线视频不卡| 麻豆国产精品777777在线| 99精品视频一区二区三区| 亚洲一区视频在线观看视频| 狠狠久久五月精品中文字幕| 亚洲人屁股眼子交8| 欧美日韩一区二区在线视频| 久久精品视频播放| 欧美高清视频一区| 欧美一级片一区| 免费在线观看成人av| 亚洲一区二区三区精品在线| 欧美一区二区性| 99爱精品视频| 欧美专区日韩视频| 亚洲一区二区欧美日韩| 久久综合狠狠| 欧美伊人精品成人久久综合97| 免费中文字幕日韩欧美| 亚洲欧美日韩视频一区| 欧美黄色一级视频| 久久躁日日躁aaaaxxxx| 国产精品播放| 亚洲国产精品一区二区久 | 欧美成人免费在线观看| 欧美日韩另类国产亚洲欧美一级| 久久久久9999亚洲精品| 欧美日韩一区二区精品| 欧美激情精品久久久久| 国产嫩草影院久久久久| 亚洲精品在线免费| 亚洲激情影视| 久久国产综合精品| 亚洲欧美日韩成人| 欧美日韩国产亚洲一区| 欧美韩日高清| 1769国内精品视频在线播放| 新片速递亚洲合集欧美合集| 宅男66日本亚洲欧美视频| 欧美成人激情在线| 免费日韩成人| 在线播放中文一区| 久久国产直播| 久久亚洲综合| 国产综合亚洲精品一区二| 午夜精品亚洲一区二区三区嫩草| 亚洲一区二区精品在线观看| 欧美日韩亚洲一区二区三区四区 | 欧美精品一区二区视频| 免费看精品久久片| 尤物在线观看一区| 久久夜色精品国产| 欧美sm重口味系列视频在线观看| 在线观看成人av电影| 久久久777| 欧美阿v一级看视频| 亚洲精品久久久久久久久久久| 老牛影视一区二区三区| 欧美激情亚洲精品| 日韩亚洲精品电影| 欧美日韩国产影院| 亚洲香蕉成视频在线观看| 欧美一级大片在线观看| 国产亚洲免费的视频看| 久久久av网站| 亚洲国产精品第一区二区三区| 亚洲精品日韩久久| 欧美色中文字幕| 亚洲综合色婷婷| 久热精品在线视频| 亚洲精品视频免费观看| 欧美日精品一区视频| 亚洲一区二区三区精品动漫| 欧美在线综合| 91久久线看在观草草青青| 欧美了一区在线观看| 在线亚洲一区二区| 久久久www成人免费精品| 亚洲大片av| 欧美精品日韩一本| 午夜精品免费| 欧美黄色精品| 性色av香蕉一区二区| 在线免费高清一区二区三区| 欧美日韩欧美一区二区| 欧美亚洲视频| 亚洲精品国产无天堂网2021| 欧美中文字幕不卡| 亚洲免费观看高清在线观看 | 国产欧美 在线欧美| 久久先锋影音| 亚洲一区二区av电影| 久久久久久久精| 中文国产一区| 亚洲国产经典视频| 国产欧美日韩亚洲| 欧美精品不卡| 久久久久久久久久久成人| 99re这里只有精品6| 久久久久欧美精品| 国产精品99久久久久久久vr| 在线日韩中文字幕| 国产农村妇女精品| 国产精品v日韩精品v欧美精品网站| 久久久久九九九九| 欧美亚洲免费电影| 一本久道综合久久精品| 亚洲第一页自拍| 久久久水蜜桃| 欧美一区2区视频在线观看| 日韩午夜中文字幕| 尤物网精品视频| 国产一区二区精品丝袜| 国产精品你懂的在线| 欧美精品日韩| 女生裸体视频一区二区三区| 欧美在线观看一区| 亚洲欧美一区二区视频| 亚洲视频 欧洲视频| 99re6热只有精品免费观看| 亚洲激情在线视频| 亚洲高清在线观看| 亚洲高清色综合| 欧美jizzhd精品欧美巨大免费| 久久精品天堂| 久久视频在线免费观看| 久久精品30| 久久久一区二区三区| 久久精品日产第一区二区| 午夜在线视频观看日韩17c| 一区二区三区毛片| 在线一区观看| 午夜亚洲影视| 久久久福利视频| 久久琪琪电影院| 麻豆精品91| 欧美黑人在线播放| 亚洲精品欧洲精品| 夜久久久久久| 亚洲欧美在线一区二区| 久久精品国产成人| 美女啪啪无遮挡免费久久网站| 欧美xxx在线观看| 欧美日韩免费视频| 国产精品永久| 精品电影在线观看| 亚洲美女免费精品视频在线观看| 一区二区三区成人精品| 午夜精品久久久久久| 久久婷婷国产麻豆91天堂| 欧美粗暴jizz性欧美20| 亚洲美女在线观看| 欧美一区二区在线| 欧美成人伊人久久综合网| 国产精品videosex极品| 国产亚洲视频在线| 亚洲伦理在线观看| 欧美在线精品免播放器视频| 麻豆freexxxx性91精品| 亚洲精品乱码久久久久久黑人| 亚洲一二区在线| 久久婷婷国产综合国色天香| 欧美日韩视频在线第一区| 国产一区二区高清视频| 亚洲欧洲一区| 久久精品二区三区| 亚洲日韩成人| 久久av免费一区| 欧美乱人伦中文字幕在线| 国产一区二区福利| 一区二区日韩欧美| 久久综合九色欧美综合狠狠| 亚洲每日在线| 快播亚洲色图| 国产一区二区高清不卡| 亚洲天堂免费观看| 麻豆久久婷婷| 亚洲欧美日韩国产综合精品二区| 免费成人小视频| 国产一区二区三区四区老人| 中国女人久久久| 亚洲国产精品第一区二区| 久久精品成人一区二区三区| 欧美亚一区二区| 亚洲精品系列|