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

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 閱讀(2336) 評(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ì)墜落到地上的最長(zhǎng)距離 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
謝謝提醒 呵呵
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美一级视频| 亚洲欧美日韩精品久久奇米色影视| 欧美一区在线看| 国产一区二区三区在线免费观看| 久久久不卡网国产精品一区| 久久精品一区二区| 在线日本欧美| 亚洲精品欧美| 国产精品一区二区久激情瑜伽| 久久精品夜色噜噜亚洲aⅴ| 久久精品日韩| 亚洲免费av片| 亚洲女性喷水在线观看一区| 狠狠色丁香久久婷婷综合_中| 美女在线一区二区| 欧美日韩二区三区| 久久精品国产一区二区电影| 蘑菇福利视频一区播放| 亚洲免费视频观看| 久久视频这里只有精品| 在线一区欧美| 久久久久一区二区三区四区| 一区二区三区视频在线播放| 欧美在线观看www| 日韩视频精品在线| 欧美在线一级视频| 亚洲午夜免费福利视频| 久久精品九九| 亚洲免费在线播放| 欧美aⅴ99久久黑人专区| 午夜国产不卡在线观看视频| 久久精品2019中文字幕| 亚洲素人在线| 另类激情亚洲| 久久在线91| 欧美日韩精品在线播放| 免费成人在线观看视频| 国产精自产拍久久久久久蜜| 亚洲国产人成综合网站| 国产毛片精品视频| 一本色道88久久加勒比精品| 亚洲高清视频在线观看| 欧美一区二区三区四区在线观看| 亚洲三级网站| 久久久精品国产免费观看同学| 亚洲永久免费观看| 欧美日韩国产色综合一二三四 | 中国女人久久久| 久久女同精品一区二区| 久久国产黑丝| 国产精品久在线观看| 亚洲人成人一区二区在线观看| 精品99视频| 欧美一区二区播放| 欧美亚洲免费高清在线观看| 国产精品激情电影| 亚洲视频在线观看视频| 中日韩美女免费视频网站在线观看| 久久一区中文字幕| 美日韩精品免费观看视频| 国产婷婷精品| 欧美在线观看一区| 久久夜色精品国产| 亚洲国产成人久久综合| 狂野欧美激情性xxxx欧美| 欧美精品久久久久久久久老牛影院 | 裸体丰满少妇做受久久99精品| 久久久久久久波多野高潮日日 | 欧美成人精品福利| 亚洲黄色毛片| 亚洲视频 欧洲视频| 国产精品第十页| 午夜视频在线观看一区| 久久综合给合| 亚洲日本免费| 欧美三级在线视频| 亚洲欧美精品在线观看| 久久一区激情| 亚洲国产中文字幕在线观看| 欧美精品乱人伦久久久久久| 日韩一级在线观看| 欧美亚洲日本一区| 永久久久久久| 欧美日韩天天操| 香蕉精品999视频一区二区| 久久精品国产综合| 亚洲精品乱码久久久久| 欧美视频在线观看 亚洲欧| 亚洲欧美一区二区三区在线 | 中文久久精品| 国外成人在线视频| 欧美激情网站在线观看| 亚洲永久免费视频| 亚洲第一视频网站| 午夜欧美精品| 亚洲欧洲在线播放| 国产欧美一区二区白浆黑人| 狼人天天伊人久久| 一片黄亚洲嫩模| 欧美.www| 欧美伊人久久大香线蕉综合69| 一色屋精品亚洲香蕉网站| 欧美日韩一区二区三区在线看| 香蕉久久久久久久av网站| 亚洲国产精品久久人人爱蜜臀| 亚洲专区在线视频| 亚洲激情视频在线观看| 国产伦精品一区二区三区视频孕妇 | 亚洲第一黄色| 久久精品av麻豆的观看方式| 亚洲精品永久免费| 黑人巨大精品欧美黑白配亚洲| 欧美日韩国产成人在线| 久久精品国产99| 亚洲欧美日韩精品久久奇米色影视 | 午夜亚洲影视| 99精品视频免费观看视频| 黄色成人免费观看| 国产精品日韩欧美一区二区三区 | 亚洲午夜视频在线| 亚洲裸体在线观看| 亚洲国产精品视频| 欧美aaa级| 久久久久www| 性欧美1819性猛交| 亚洲综合国产| 亚洲永久精品大片| 亚洲一区中文| 亚洲天堂网在线观看| 一区二区欧美在线观看| 亚洲经典在线| 亚洲日本激情| 亚洲精品黄色| 亚洲乱码国产乱码精品精98午夜| 国语精品中文字幕| 狠色狠色综合久久| 尹人成人综合网| 在线免费观看视频一区| 黄色成人av网站| 亚洲第一精品久久忘忧草社区| 国产中文一区二区| 激情亚洲网站| 亚洲第一在线综合网站| 亚洲国内高清视频| 亚洲欧洲综合另类| 亚洲麻豆国产自偷在线| 中日韩视频在线观看| 亚洲一区成人| 欧美亚洲在线播放| 久久久蜜臀国产一区二区| 狂野欧美激情性xxxx欧美| 欧美成人69| 亚洲黄色影片| 一区二区三区 在线观看视频| 亚洲午夜国产成人av电影男同| 亚洲一区在线直播| 久久精品在线观看| 欧美成人国产| 国产精品女人毛片| 韩日视频一区| 亚洲免费观看高清完整版在线观看| 亚洲作爱视频| 久久精品二区亚洲w码| 麻豆九一精品爱看视频在线观看免费| 蜜桃精品一区二区三区 | 久久gogo国模裸体人体| 看欧美日韩国产| 亚洲伦理自拍| 欧美一区二区三区另类| 欧美成人嫩草网站| 国产精品无人区| 亚洲国产一区视频| 欧美一区=区| 亚洲第一二三四五区| 亚洲永久免费av| 欧美成人精品一区二区| 国产精品视频自拍| 亚洲日本在线观看| 久久久.com| 亚洲美女在线视频| 久久亚洲电影| 国产精品专区第二| 亚洲免费电影在线| 久久夜色精品| 亚洲一二三区精品| 欧美精品一区二区三| 国内一区二区三区在线视频| 99这里只有精品| 另类天堂av| 午夜宅男欧美| 欧美性色aⅴ视频一区日韩精品| 在线观看日韩av先锋影音电影院| 亚洲天堂视频在线观看| 欧美激情在线免费观看| 午夜一区在线| 国产精品护士白丝一区av| 91久久国产综合久久91精品网站 | 亚洲区国产区| 美女国产一区| 久久激情五月婷婷|