博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3440 House Man
阅读量:4482 次
发布时间:2019-06-08

本文共 3733 字,大约阅读时间需要 12 分钟。

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3174    Accepted Submission(s): 1325

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
 

 

Author
jyd
 

 

Source
 

 

Recommend
We have carefully selected several similar problems for you:       
#include
#include
#include
#include
#include
#define MAXN 1100#define MAXM MAXN*MAXN#define INF 0x7fffffffusing namespace std;queue
que;int t,n,d,tot,kase;int dis[MAXN],vis[MAXN],num[MAXN],id;int to[MAXM],net[MAXM],cap[MAXM],head[MAXN];struct House{ int high;int no; }arr[MAXN];int cmp(House a,House b){ return a.high
n) return -1; for(int i=head[now];i;i=net[i]){ if(dis[to[i]]>dis[now]+cap[i]){ dis[to[i]]=dis[now]+cap[i]; if(!vis[to[i]]){ vis[to[i]]=1; que.push(to[i]); } } } } return dis[t];}int main(){ scanf("%d",&t); while(t--){ memset(head,0,sizeof(head)); scanf("%d%d",&n,&d);tot=0; for (int i=1;i<=n;i++){ scanf("%d",&arr[i].high); arr[i].no=i; if(i!=n) add(i+1,i,-1); } sort(arr+1,arr+n+1,cmp); for(int i=1;i
v) swap(u,v); add(u,v,d); } int u=arr[1].no,v=arr[n].no; if(u>v) swap(u,v); printf("Case %d: %d\n",++kase,spfa(u,v,n)); }}

 

转载于:https://www.cnblogs.com/cangT-Tlan/p/9091588.html

你可能感兴趣的文章
洛谷P1080 国王游戏【大数】【贪心】
查看>>
Python 字符串相似性的几种度量方法
查看>>
OpenMP编程的任务调度控制
查看>>
卡特兰(Catalan)数列
查看>>
设计模式(一)工厂模式Factory(创建型)
查看>>
Warshall算法
查看>>
Python之匿名函数
查看>>
PhoneGap 3.0 安装
查看>>
每天一个小算法(2)----合并两个有序链表
查看>>
IOS开发把一个结构体放到数组中
查看>>
cglib动态代理(即AOP)
查看>>
08 H5新增input元素
查看>>
linux中安装软件的集中方法
查看>>
Express中间件,看这篇文章就够了(#^.^#)
查看>>
《构建之法》(五)
查看>>
创建django项目
查看>>
Linux Bash基本功能
查看>>
一则小脚本(工作中用)
查看>>
软件工程结对作业
查看>>
Keil 4.0 生成bin文件
查看>>