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

hdu3440(差分約束)

題目網址: http://acm.hdu.edu.cn/showproblem.php?pid=3440 

House Man

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 446    Accepted Submission(s): 157


Problem Description
In Fuzhou, there is a crazy super man. He can’t fly, but he could jump from housetop to housetop. Today he plans to use N houses to hone his house hopping skills. He will start at the shortest house and make N-1 jumps, with each jump taking him to a taller house than the one he is jumping from. When finished, he will have been on every house exactly once, traversing them in increasing order of height, and ending up on the tallest house.
The man can travel for at most a certain horizontal distance D in a single jump. To make this as much fun as possible, the crazy man want to maximize the distance between the positions of the shortest house and the tallest house.
The crazy super man have an ability—move houses. So he is going to move the houses subject to the following constraints:
1. All houses are to be moved along a one-dimensional path.
2. Houses must be moved at integer locations along the path, with no two houses at the same location.
3. Houses must be arranged so their moved ordering from left to right is the same as their ordering in the input. They must NOT be sorted by height, or reordered in any way. They must be kept in their stated order.
4. The super man can only jump so far, so every house must be moved close enough to the next taller house. Specifically, they must be no further than D apart on the ground (the difference in their heights doesn't matter).
Given N houses, in a specified order, each with a distinct integer height, help the super man figure out the maximum possible distance they can put between the shortest house and the tallest house, and be able to use the houses for training.
 

Input
In the first line there is an integer T, indicates the number of test cases.(T<=500)
Each test case begins with a line containing two integers N (1 ≤ N ≤ 1000) and D (1 ≤ D ≤1000000). The next line contains N integer, giving the heights of the N houses, in the order that they should be moved. Within a test case, all heights will be unique.
 

Output
For each test case , output “Case %d: “first where d is the case number counted from one, then output a single integer representing the maximum distance between the shortest and tallest house, subject to the constraints above, or -1 if it is impossible to lay out the houses. Do not print any blank lines between answers.
 

Sample Input
3 4 4 20 30 10 40 5 6 20 34 54 10 15 4 2 10 20 16 13
 

Sample Output
Case 1: 3 Case 2: 3 Case 3: -1

// Bellman_Ford 
#include <stdio.h>
#include 
<memory>
#include 
<iostream>
#include 
<algorithm>
#include 
<cstring>
#include 
<vector>
#include 
<map>
#include 
<cmath>
#include 
<set>
#include 
<queue>
#include 
<time.h> 
#include 
<limits>
using namespace std;
#define typev int
#define N 1005
#define inf 0x7fffffff 
#define E (N*5) 
const double pi = acos(-1.0); 
struct e{
    
int st, ed; 
    typev len;  
    
void set(int _st, int _ed, typev _len){
        st 
= _st; 
        ed 
= _ed; 
        len 
= _len; 
    }
}es[E];
struct node{
    
int h; 
    
int i; 
}nodes[N];
e
* fir[N]; 
int n, en, d;
int st, ed; 
int vis[N], t[N], que[N]; 
typev dist[N]; 
inline 
bool cmp(node n1, node n2){
    
return n1.h < n2.h; 
}
inline 
bool relax(int st, int ed, int len){
    
if(dist[st] < inf && dist[ed] > dist[st] + len){
        dist[ed] 
= dist[st] + len;
        
return true
    }
    
return false
}
bool Bellman_Ford(int n, int st){  //返回true表示有負環
    int i, j; 
    
bool flag; 
    
for(i = 0; i < n; i++) dist[i] = inf; 
    dist[st] 
= 0
    
for(i = 0; i < n; i++){
        flag 
= false
        
for(j = 0; j < en; j++){
            
if(relax(es[j].st, es[j].ed, es[j].len)) flag = true
        }
        
if(!flag) break
    }
    
return flag;  
}
int cnt = 0
int main(){
#ifndef ONLINE_JUDGE
    freopen(
"in.txt""r", stdin); 
    
//freopen("out.txt", "w", stdout); 
#endif 

    
int t, i, ans, u, v;
    scanf(
"%d"&t);
    
while(t--){
        scanf(
"%d%d"&n, &d);
        
for(i = 0; i < n; i++){
            scanf(
"%d"&nodes[i].h);
            nodes[i].i 
= i; 
        }
        en 
= st = ed = 0
        sort(nodes, nodes
+n, cmp); 
        st 
= nodes[0].i; 
        ed 
= nodes[n - 1].i; 
        
if(st > ed) swap(st, ed); 
        
for(i = 0; i < n; i++) fir[i] = NULL; 
        
for(i = 1; i < n; i++){
            es[en
++].set(i, i-1-1); 
            u 
= nodes[i].i; 
            v 
= nodes[i - 1].i; 
            
if(u < v){
                es[en
++].set(u, v, d); 
            }
else es[en++].set(v, u, d); 
        } 
        
if(!Bellman_Ford(n, st)) ans = dist[ed];
        
else ans = -1
        printf(
"Case %d: %d\n"++cnt, ans);

    }
    
return 0;
}



posted on 2011-01-23 01:13 tw 閱讀(506) 評論(0)  編輯 收藏 引用 所屬分類: HDU題解

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿

文章分類

文章檔案

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产亚洲欧美一区二区| 久久久成人网| 国产欧美日本在线| 国产精品红桃| 国产精品中文字幕在线观看| 国产精品一区免费在线观看| 国产欧美一区二区色老头| 国产一区二区久久| 狠狠色综合网| 亚洲精品永久免费精品| 亚洲天堂成人在线观看| 午夜日韩在线| 开心色5月久久精品| 欧美激情精品久久久六区热门 | 国产精品国产自产拍高清av| 欧美日韩国产123| 国产精品第2页| 一区二区三区在线免费播放| 亚洲国产日韩美| 亚洲午夜一区二区| 老鸭窝毛片一区二区三区| 亚洲日本欧美| 中文精品视频| 久久久久一本一区二区青青蜜月| 欧美好骚综合网| 国产欧美日韩91| 亚洲看片一区| 美女国产一区| 亚洲欧美www| 欧美精品一区在线发布| 国产手机视频一区二区| 日韩五码在线| 美女图片一区二区| 亚洲资源在线观看| 欧美另类在线播放| 亚洲成色777777在线观看影院| 亚洲一区www| 亚洲国产综合在线| 久久激情五月激情| 国产精品sm| 日韩午夜视频在线观看| 快she精品国产999| 亚洲一区二区三区777| 欧美黄色影院| 91久久香蕉国产日韩欧美9色| 欧美在线视频免费播放| 中文av字幕一区| 欧美三级视频在线| 日韩天堂在线观看| 亚洲第一区中文99精品| 久久精品视频免费| 国产一级一区二区| 久久国产主播| 午夜精品在线视频| 国产欧美日韩中文字幕在线| 亚洲欧美高清| 中文精品在线| 国产精品久久久久av| 亚洲午夜一级| 亚洲午夜黄色| 国产精品综合| 欧美在线一二三区| 欧美一级播放| 韩国三级电影久久久久久| 久久久久九九视频| 久久精品夜色噜噜亚洲aⅴ| 国户精品久久久久久久久久久不卡 | 久久精品在线观看| 国产精品亚洲视频| 午夜一区二区三区不卡视频| 国产精品第一页第二页第三页| 99视频精品在线| 日韩视频三区| 国产精品美女久久久浪潮软件| 一区二区三区日韩精品| 亚洲美女啪啪| 欧美日韩一级片在线观看| 亚洲网站在线播放| 亚洲欧洲av一区二区三区久久| 国产日韩亚洲| 欧美成人精品一区二区| 欧美韩国在线| 欧美一区二区在线观看| 久久久久久亚洲综合影院红桃| 亚洲成人中文| 一区二区三区免费网站| 国产一区二区精品久久| 欧美国产在线电影| 欧美午夜视频在线| 老司机免费视频久久| 欧美激情在线观看| 欧美一区三区三区高中清蜜桃| 久久国产精品72免费观看| 亚洲全黄一级网站| 亚洲一区美女视频在线观看免费| 国产综合精品| 99精品99| 在线成人h网| 中文欧美日韩| 亚洲精品一区二区三区婷婷月| 亚洲一区二区欧美日韩| 亚洲日本中文字幕| 午夜精品一区二区三区四区| 亚洲片区在线| 欧美在线免费观看| 亚洲图片你懂的| 久久综合中文色婷婷| 羞羞答答国产精品www一本| 美女主播一区| 久久久噜噜噜久久狠狠50岁| 欧美伦理在线观看| 久久午夜国产精品| 国产精品麻豆成人av电影艾秋| 欧美刺激性大交免费视频| 国产精品色网| 一本色道婷婷久久欧美| 亚洲欧洲一区二区三区| 久久婷婷蜜乳一本欲蜜臀| 欧美专区福利在线| 国产精品美女999| 日韩一级精品| 99在线精品观看| 欧美成人资源网| 欧美.www| 在线成人免费观看| 久久国产精品久久国产精品| 午夜精品久久久久99热蜜桃导演| 欧美人与禽猛交乱配| 亚洲国产欧美一区二区三区丁香婷| 国产亚洲精品bt天堂精选| 亚洲一区免费观看| 亚洲综合精品四区| 欧美午夜精品一区| 欧美精品亚洲一区二区在线播放| 99天天综合性| 欧美激情一区二区在线 | 久久久91精品国产| 久久久精品动漫| 国产农村妇女毛片精品久久麻豆 | 亚洲高清资源综合久久精品| 欧美一区二区三区久久精品 | 亚洲一区二区精品视频| 欧美福利专区| 亚洲激情综合| 亚洲精品婷婷| 欧美日韩国产亚洲一区| 亚洲美女中文字幕| 亚洲无吗在线| 国产精品自在线| 久久精品国产999大香线蕉| 久久综合久久综合久久综合| 在线精品高清中文字幕| 欧美a级在线| 99re8这里有精品热视频免费| 亚洲永久免费av| 国产一区再线| 欧美丰满高潮xxxx喷水动漫| 亚洲毛片一区二区| 欧美亚洲一区二区在线| 国内精品视频在线观看| 蜜臀av性久久久久蜜臀aⅴ| 亚洲国产精品久久久久秋霞不卡 | 一区在线观看| 欧美国产日韩在线| aa级大片欧美| 久久天天躁夜夜躁狠狠躁2022| 亚洲风情亚aⅴ在线发布| 欧美日本亚洲| 欧美一区午夜视频在线观看| 麻豆成人在线| 一区二区三区.www| 欧美视频二区| 久久视频在线看| 一区二区欧美亚洲| 老司机午夜精品视频| 亚洲特级片在线| 国产一区二区日韩精品欧美精品| 久久麻豆一区二区| 99精品免费视频| 久久人人爽爽爽人久久久| 欧美国产日韩亚洲一区| 香蕉久久国产| 亚洲精品资源| 六十路精品视频| 亚洲一区二区av电影| 亚洲人成网站777色婷婷| 国产精品日韩在线| 久久在线播放| 一区二区三区成人| 欧美国产免费| 久久爱www久久做| 一区二区三区**美女毛片| 亚洲精品午夜| 国产精品麻豆成人av电影艾秋| 蜜臀av性久久久久蜜臀aⅴ| 午夜激情综合网| 99re热这里只有精品视频| 久久久久久久久久久久久9999| 亚洲二区视频| 亚洲大胆女人|