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

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 閱讀(2336) 評論(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>
            亚洲精品日韩综合观看成人91 | 久久国产高清| 欧美激情视频一区二区三区在线播放| 欧美在线网站| 久久精品欧美日韩| 久久久久久亚洲综合影院红桃| 久久久久久一区二区三区| 久久精品视频va| 老司机一区二区三区| 欧美激情视频一区二区三区在线播放 | 亚洲欧美日韩一区在线| 亚洲最新视频在线播放| 中文有码久久| 久久精品一区二区| 欧美高清不卡| 国产精品一区二区久久精品| 国产精品一区=区| 亚洲国产成人久久| 亚洲天堂久久| 久久久久国产一区二区| 欧美黄色aa电影| 亚洲一区综合| 欧美黄色小视频| 国产精品自拍视频| 日韩一二三区视频| 久久噜噜亚洲综合| 亚洲视频高清| 欧美激情在线狂野欧美精品| 国产精品少妇自拍| 亚洲精品日韩久久| 久久免费一区| 亚洲欧美日韩成人高清在线一区| 久久久亚洲人| 国产伦一区二区三区色一情| 亚洲人成亚洲人成在线观看图片 | 另类春色校园亚洲| 亚洲无线观看| 麻豆乱码国产一区二区三区| 国产精品视区| 亚洲视频网在线直播| 欧美大片一区二区| 欧美一区二区在线免费观看| 欧美日一区二区三区在线观看国产免| 伊伊综合在线| 久久视频这里只有精品| 亚洲欧美高清| 国产精品实拍| 亚洲欧美网站| av成人免费在线| 欧美国产先锋| 亚洲人成人77777线观看| 久久躁狠狠躁夜夜爽| 午夜国产不卡在线观看视频| 欧美日韩一区在线观看| 一区二区欧美在线观看| 亚洲国产精品va在线看黑人| 在线午夜精品自拍| 欧美三级中文字幕在线观看| 在线视频中文亚洲| 亚洲免费观看高清完整版在线观看熊 | 亚洲精品欧美日韩| 欧美日韩国产限制| 一区二区三区色| 国产一区二区电影在线观看 | 国产精品欧美久久| 国产亚洲精品aa| 久久午夜激情| 香蕉久久夜色精品国产| 欧美视频福利| 日韩一级网站| 亚洲日韩欧美视频一区| 久热精品在线视频| 亚洲国产你懂的| 亚洲第一偷拍| 欧美久久久久久蜜桃| 一本到高清视频免费精品| 亚洲精品欧美在线| 国产精品免费看片| 久久精品国产综合精品| 久久精品官网| 亚洲狼人综合| 亚洲线精品一区二区三区八戒| 国产精品久久久久久久午夜片| 新片速递亚洲合集欧美合集| 欧美一区免费视频| 亚洲国产一区二区在线| 亚洲免费观看高清在线观看| 国产精品久久国产愉拍 | 欧美一区三区三区高中清蜜桃| 亚洲综合色视频| 黄色在线一区| 亚洲美女黄色| 好看不卡的中文字幕| 亚洲国产综合91精品麻豆| 国产精品va在线播放| 久久综合电影| 欧美三日本三级少妇三2023| 久久理论片午夜琪琪电影网| 男女精品网站| 欧美一级视频| 欧美极品一区| 亚洲永久网站| 欧美α欧美αv大片| 欧美大色视频| 午夜精品亚洲| 美国十次了思思久久精品导航| 99亚洲精品| 久久久久国产一区二区| 宅男在线国产精品| 久久国产精品久久久久久久久久 | 欧美日韩成人在线播放| 久久久999国产| 欧美日韩一区二区在线播放| 久久视频这里只有精品| 欧美日韩一区二区三区四区在线观看 | 亚洲蜜桃精久久久久久久| 亚洲欧美在线视频观看| 99国产精品私拍| 麻豆精品国产91久久久久久| 久久精品日韩| 国产精品网站视频| 亚洲最新在线视频| 亚洲日本一区二区三区| 久久精品日韩| 久久精品国产欧美激情| 国产精品天天看| 在线一区视频| 亚洲午夜精品视频| 欧美日韩mv| 亚洲伦理一区| 99在线精品观看| 欧美黄色一区二区| 亚洲国产精品悠悠久久琪琪| 亚洲国产精品小视频| 久久欧美中文字幕| 猫咪成人在线观看| 影音先锋亚洲电影| 久久精品五月| 欧美aa在线视频| 亚洲国产精品久久久久| 免费成人你懂的| 亚洲黄色在线看| 99ri日韩精品视频| 欧美日韩一区精品| 亚洲午夜久久久久久尤物| 亚洲男人天堂2024| 国产精品视频999| 欧美一区二区在线视频| 久久亚洲春色中文字幕| 狠狠色香婷婷久久亚洲精品| 久久久久亚洲综合| 亚洲国产裸拍裸体视频在线观看乱了中文 | 欧美激情区在线播放| 亚洲国产日韩欧美在线99| 亚洲国产一区在线观看| 欧美精品激情在线观看| 亚洲精品国产品国语在线app| 日韩午夜激情av| 国产精品www| 欧美一区二区视频在线观看2020| 久久综合久久综合久久| 亚洲国产高清高潮精品美女| 欧美激情自拍| 亚洲欧美日韩爽爽影院| 蜜臀va亚洲va欧美va天堂| 亚洲精品一区二区三区樱花| 欧美午夜精品久久久久久久 | 国产精品久久久一区二区三区| 午夜精品久久久久久久白皮肤| 久久免费视频在线观看| 亚洲黄色有码视频| 国产精品电影网站| 久热精品视频在线观看一区| 一区二区三区 在线观看视| 久久蜜桃香蕉精品一区二区三区| 亚洲另类在线一区| 国产精品久久久一区二区| 毛片av中文字幕一区二区| 99精品欧美一区| 免费影视亚洲| 性久久久久久久久| 99精品视频一区| 依依成人综合视频| 国产精品久在线观看| 农夫在线精品视频免费观看| 亚洲女性喷水在线观看一区| 欧美二区视频| 欧美综合国产| 亚洲一区二区三区精品视频| 亚洲国产欧美一区| 国产性色一区二区| 国产精品久久久久久久免费软件 | 日韩午夜视频在线观看| 麻豆免费精品视频| 亚洲午夜免费视频| 亚洲乱码国产乱码精品精 | 亚洲国产精品999| 久久在线播放| 午夜伦理片一区| 亚洲一卡久久|