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

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>
            亚洲亚洲精品在线观看| 亚洲看片免费| 久久国产精品一区二区三区| 国产一区在线观看视频| 久久人人97超碰精品888| 久久色在线观看| 99精品国产高清一区二区 | 亚洲黄色影片| 亚洲人成网站色ww在线| 欧美午夜美女看片| 久久综合亚洲社区| 欧美久久久久免费| 久久电影一区| 欧美黄色网络| 久久精品国内一区二区三区| 蜜桃av综合| 午夜精品久久久久久99热| 久久久久久午夜| 亚洲一区二区三区四区中文| 欧美在线视频播放| 夜夜躁日日躁狠狠久久88av| 性18欧美另类| 99精品国产福利在线观看免费| 午夜精品福利视频| 亚洲精品国产精品国自产在线 | 99精品视频免费| 尤物精品在线| 亚洲女性喷水在线观看一区| 亚洲日本激情| 欧美影院成人| 亚洲男同1069视频| 欧美黄色一级视频| 久久免费视频在线观看| 欧美亚洲不卡| 亚洲国产网站| 激情综合色综合久久| 亚洲视频在线观看| 99精品欧美一区二区三区综合在线 | 久久久久综合一区二区三区| 国产精品福利在线观看网址| 亚洲国产高清视频| 在线日韩成人| 久久久久成人精品免费播放动漫| 亚洲欧美在线观看| 欧美日韩视频一区二区三区| 亚洲国产综合视频在线观看| 亚洲第一在线视频| 欧美伊人久久久久久午夜久久久久 | 亚洲欧美视频在线观看视频| 欧美片在线观看| 亚洲国产欧美不卡在线观看| 在线看片一区| 久久视频在线视频| 久久久综合网站| 国产一区欧美| 久久精品国内一区二区三区| 久久久免费观看视频| 国产中文一区二区三区| 欧美一区二区| 久久亚洲欧美| 亚洲国产精品va在线看黑人 | 欧美日韩在线免费| 亚洲乱码国产乱码精品精天堂| 亚洲伦理一区| 欧美日韩国产专区| 这里只有精品视频在线| 午夜精品999| 国产欧美丝祙| 久久精品视频va| 欧美高清不卡| 亚洲精品一区二区三| 欧美日韩在线播放三区| 亚洲视频欧洲视频| 久久精品视频在线| 在线日韩成人| 欧美日韩一区二区在线播放| 亚洲一区二区三区777| 久久精品官网| 亚洲激情在线视频| 欧美日韩亚洲国产一区| 亚洲欧美一区二区激情| 欧美jizz19性欧美| 一区二区三区高清在线| 国产精品区二区三区日本| 久久精品久久99精品久久| 亚洲第一主播视频| 亚洲欧美亚洲| 亚洲国产精品一区| 国产精品成人一区二区三区吃奶| 久久国产精品久久国产精品| 亚洲高清资源| 久久精品亚洲国产奇米99| 亚洲久色影视| 国产欧美视频在线观看| 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲美女在线看| 欧美中文字幕视频在线观看| 1000部国产精品成人观看| 欧美日韩色综合| 久久九九电影| 亚洲一区二区毛片| 亚洲国产精品成人一区二区 | 99成人免费视频| 久久三级福利| 亚洲欧美日本伦理| 亚洲电影网站| 国产欧美一区二区精品忘忧草| 欧美承认网站| 久久久久久9| 亚洲欧美欧美一区二区三区| 亚洲激情视频网站| 免费永久网站黄欧美| 欧美一级艳片视频免费观看| 99精品国产99久久久久久福利| 一区在线免费| 国产欧美激情| 欧美少妇一区| 欧美福利在线观看| 开心色5月久久精品| 欧美一区二区性| 午夜精品福利视频| 亚洲一区二区视频在线| 99国产精品视频免费观看一公开| 亚洲第一区在线观看| 免费在线欧美视频| 久久裸体视频| 久久久久久999| 欧美在线视频不卡| 欧美一区2区视频在线观看 | 亚洲国产婷婷香蕉久久久久久99| 国产亚洲a∨片在线观看| 国产精品久久久久永久免费观看| 欧美日韩亚洲一区三区| 欧美激情四色| 欧美精品久久99| 欧美精品一区二区蜜臀亚洲| 牛牛精品成人免费视频| 欧美成人第一页| 欧美黄色成人网| 欧美激情视频网站| 欧美伦理a级免费电影| 欧美日韩国产黄| 欧美日韩视频在线第一区| 欧美日韩在线看| 国产精品久久中文| 国产日韩欧美一二三区| 国产在线乱码一区二区三区| 国产一区二区三区在线观看网站 | 久久亚洲影院| 欧美成人一二三| 亚洲精品极品| 亚洲社区在线观看| 欧美一区二区三区精品电影| 久久国产夜色精品鲁鲁99| 久久尤物视频| 欧美精品aa| 国产精品亚洲综合天堂夜夜| 国产在线不卡精品| 亚洲精品国产欧美| 亚洲欧美一区在线| 久久综合九色综合欧美就去吻| 欧美激情精品久久久久久| 亚洲美女区一区| 欧美一区二区高清在线观看| 欧美不卡视频| 国产精品蜜臀在线观看| 亚洲高清久久网| 亚洲桃色在线一区| 久久精品女人天堂| 91久久国产精品91久久性色| 亚洲男人影院| 欧美电影电视剧在线观看| 国产精品福利av| 亚洲激情网站| 性欧美videos另类喷潮| 欧美激情综合| 亚洲欧美中文字幕| 欧美了一区在线观看| 国产午夜精品久久久| 99国产精品自拍| 久久久亚洲精品一区二区三区| 亚洲精品激情| 老司机久久99久久精品播放免费| 国产精品久久久久久久午夜片 | 国产日产精品一区二区三区四区的观看方式 | 在线日韩电影| 午夜精品久久久久久久久久久久| 免费精品视频| 亚欧成人精品| 欧美视频在线观看一区| 亚洲片区在线| 久久午夜影视| 亚洲男同1069视频| 欧美日韩在线另类| 亚洲精品久久久久久下一站| 久久久久久久综合狠狠综合| 中日韩男男gay无套| 欧美激情综合亚洲一二区| 亚洲第一天堂av| 老司机67194精品线观看|