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

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 閱讀(2348) 評論(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>
            国产乱码精品1区2区3区| 国产在线麻豆精品观看| 99精品欧美一区二区三区| 欧美高清在线一区| 欧美大片第1页| 一本久道久久久| 一区二区三区久久久| 欧美日韩中文字幕| 午夜精品网站| 久久久999成人| 亚洲人午夜精品免费| 亚洲免费观看在线视频| 国产精品毛片a∨一区二区三区| 欧美一级网站| 久久免费视频在线| 一区二区不卡在线视频 午夜欧美不卡在| 亚洲精品乱码久久久久久黑人| 欧美美女操人视频| 午夜亚洲伦理| 久久免费99精品久久久久久| 日韩视频国产视频| 亚洲视频欧美视频| 韩国欧美国产1区| 亚洲福利视频一区| 欧美三级电影大全| 久久全球大尺度高清视频| 欧美岛国在线观看| 欧美在线一二三| 久久天天躁夜夜躁狠狠躁2022| 99re热这里只有精品视频 | 亚洲精品久久久久久一区二区| 亚洲人成人一区二区三区| 国产毛片精品国产一区二区三区| 欧美成人在线免费视频| 国产精品久久国产精品99gif| 久久手机精品视频| 国产精品第一区| 欧美国产精品中文字幕| 国产欧美日韩视频| 日韩视频在线免费观看| ●精品国产综合乱码久久久久| 亚洲一区二区免费| 日韩视频精品在线| 久久免费国产精品1| 欧美在线资源| 欧美网站在线观看| 亚洲国产精品一区在线观看不卡| 国产欧美一区二区三区沐欲| 亚洲欧洲日产国码二区| 在线播放日韩欧美| 久久国产精品一区二区三区| 亚洲综合首页| 欧美福利视频一区| 欧美激情第1页| 影音先锋亚洲精品| 久久精品五月| 久久久久久久久久看片| 国产精品视频999| 在线一区二区日韩| 亚洲欧美成人网| 欧美三级网页| 日韩亚洲成人av在线| 亚洲精品国久久99热| 美女精品在线| 欧美国产日韩视频| 亚洲国产高清在线观看视频| 久久婷婷久久一区二区三区| 久久久青草婷婷精品综合日韩 | 欧美午夜精品久久久久久浪潮 | 美女脱光内衣内裤视频久久影院| 国产亚洲精品aa午夜观看| 亚洲欧美国产视频| 久久成人一区二区| 狠狠色狠狠色综合日日小说| 欧美一站二站| 麻豆精品传媒视频| 在线成人欧美| 欧美国产亚洲另类动漫| 亚洲激情网站| 亚洲一区二区三区四区视频| 国产精品麻豆欧美日韩ww| 亚洲影视在线| 久久精品中文| 亚洲国产一区二区三区青草影视| 美女999久久久精品视频| 亚洲国产一区在线| 亚洲性夜色噜噜噜7777| 国产视频亚洲| 狼人天天伊人久久| 99亚洲视频| 久久精品中文字幕一区二区三区| 伊人久久大香线蕉综合热线 | 亚洲欧美精品| 免费看黄裸体一级大秀欧美| 99精品国产热久久91蜜凸| 欧美亚韩一区| 久久久久久久综合狠狠综合| 亚洲国产欧美一区二区三区丁香婷| 日韩一级裸体免费视频| 国产伦精品一区二区三区免费 | 欧美视频在线观看免费| 欧美一区二区三区免费观看视频| 免费在线看一区| 亚洲香蕉视频| 亚洲大胆美女视频| 国产精品精品视频| 美腿丝袜亚洲色图| 午夜国产一区| 亚洲人成亚洲人成在线观看图片| 性欧美办公室18xxxxhd| 亚洲国内精品在线| 国产精品亚洲片夜色在线| 免费不卡在线观看| 午夜在线精品偷拍| 亚洲免费激情| 欧美国产日韩一二三区| 欧美在线视频一区| 亚洲视频欧美在线| 亚洲国产精品久久精品怡红院| 国产精品地址| 欧美人与性动交cc0o| 久久久精品国产免费观看同学| 中文精品视频| 亚洲人成网站777色婷婷| 久久躁日日躁aaaaxxxx| 亚洲欧美日韩国产成人| 日韩视频在线观看国产| 亚洲成人在线视频网站| 国产日韩欧美精品在线| 国产精品乱人伦中文| 欧美日韩精选| 欧美国产高清| 美女日韩在线中文字幕| 久久久精品网| 久久不射网站| 性欧美xxxx大乳国产app| 正在播放欧美视频| 日韩视频欧美视频| 日韩亚洲精品视频| 亚洲人成免费| 亚洲精品国产精品乱码不99按摩| 欧美国产欧美亚洲国产日韩mv天天看完整 | 欧美一区免费| 亚洲欧美一区二区激情| 亚洲午夜在线观看| 亚洲婷婷国产精品电影人久久| 亚洲看片一区| 一区二区三区日韩精品视频| 日韩天堂在线视频| 一本色道久久综合| 中文亚洲免费| 亚洲一区二区综合| 亚洲欧美日韩另类精品一区二区三区| 一本一本久久| 亚洲男人的天堂在线| 亚洲欧美视频| 欧美在线看片| 久久综合网hezyo| 免费成人在线视频网站| 欧美成人精品一区| 亚洲国产精品成人综合色在线婷婷| 欧美高清不卡| 亚洲精品社区| 亚洲欧美激情一区二区| 久久精品国产99精品国产亚洲性色| 欧美专区在线播放| 麻豆精品视频| 欧美日韩成人在线| 国产精品综合色区在线观看| 国外成人免费视频| 亚洲人成毛片在线播放| 中文在线不卡视频| 欧美专区亚洲专区| 亚洲福利视频一区| 亚洲——在线| 久久综合国产精品台湾中文娱乐网| 免费毛片一区二区三区久久久| 欧美日韩卡一卡二| 国精品一区二区| 亚洲美女精品一区| 欧美一区二区三区免费视| 欧美顶级艳妇交换群宴| 一本色道久久综合亚洲精品高清| 亚洲欧美日韩高清| 欧美xx视频| 国产乱码精品1区2区3区| 亚洲国内精品| 欧美制服丝袜第一页| 亚洲第一网站| 欧美在线观看天堂一区二区三区 | 亚洲一区二区三区在线看| 久久综合激情| 国产精品一二一区| 99re热精品| 乱码第一页成人| 亚洲欧美国产高清| 欧美护士18xxxxhd| 伊人蜜桃色噜噜激情综合| 亚洲欧美久久久| 亚洲激情第一区|