Day4 - I - Trucking HDU - 2962
For the given cargo truck, maximizing the height of the goods transported is equivalent to maximizing the amount of goods transported. For safety reasons, there is a certain height limit for the cargo truck which cannot be exceeded.
InputThe input consists of a number of cases. Each case starts with two integers, separated by a space, on a line. These two integers are the number of cities (C) and the number of roads (R). There are at most 1000 cities, numbered from 1. This is followed by R lines each containing the city numbers of the cities connected by that road, the maximum height allowed on that road, and the length of that road. The maximum height for each road is a positive integer, except that a height of -1 indicates that there is no height limit on that road. The length of each road is a positive integer at most 1000. Every road can be travelled in both directions, and there is at most one road connecting each distinct pair of cities. Finally, the last line of each case consists of the start and end city numbers, as well as the height limit (a positive integer) of the cargo truck. The input terminates when C = R = 0.OutputFor each case, print the case number followed by the maximum height of the cargo truck allowed and the length of the shortest route. Use the format as shown in the sample output. If it is not possible to reach the end city from the start city, print "cannot reach destination" after the case number. Print a blank line between the output of the cases.Sample Input
5 6
1 2 7 5
1 3 4 2
2 4 -1 10
2 5 2 4
3 4 10 1
4 5 8 5
1 5 10
5 6
1 2 7 5
1 3 4 2
2 4 -1 10
2 5 2 4
3 4 10 1
4 5 8 5
1 5 4
3 1
1 2 -1 100
1 3 10
0 0
Sample Output
Case 1:
maximum height = 7
length of shortest route = 20 Case 2:
maximum height = 4
length of shortest route = 8 Case 3:
cannot reach destination 思路:
读完题,发现没有告诉高度的范围,只告诉了最大值,然后问题是2维比较,时间有10k ms,就想到二分高度,判断时就只需要判断高度,然后正常最短路算法即可,
注意输出格式(PE三发)
const int INF = 0x3f3f3f3f;
int G[][], C, R, H[][], vis[], d[], Start, End, LimitHeight; struct Node {
int u, sum;
Node(int _u, int _sum):u(_u), sum(_sum) {}
bool operator<(const Node &a) const {
return a.sum < sum;
}
}; void init() {
for(int i = ; i <= C; ++i)
for(int j = ; j <= C; ++j) {
G[i][j] = ;
H[i][j] = ;
}
} int check(int height) {
for(int i = ; i <= C; ++i) {
vis[i] = ;
d[i] = INF;
}
priority_queue<Node> q;
q.push(Node(Start, ));
d[Start] = ;
while(!q.empty()) {
Node now = q.top();
q.pop();
int u = now.u;
if(vis[u]++) continue;
if(u == End) return d[End];
for(int i = ; i <= C; ++i) {
if(G[u][i] && (H[u][i] == - || H[u][i] >= height) && d[i] > d[u] + G[u][i]) {
d[i] = d[u] + G[u][i];
q.push(Node(i, d[i]));
}
}
}
return ;
} int main() {
ios::sync_with_stdio(false);
int t1, t2, t3, t4, kase = ;
while(cin >> C >> R && C+R) {
init();
for(int i = ; i <= R; ++i) {
cin >> t1 >> t2 >> t3 >> t4;
G[t1][t2] = G[t2][t1] = t4;
H[t1][t2] = H[t2][t1] = t3;
}
cin >> Start >> End >> LimitHeight;
int l = , r = LimitHeight, mid, tmp, Height=-, path=-;
while(l <= r) {
mid = (r + l) >> ;
tmp = check(mid);
if(tmp > ) {
Height = mid;
path = tmp;
l = mid + ;
} else
r = mid - ;
}
if(kase) cout << "\n";
cout << "Case " << ++kase << ":\n";
if(Height == -) {
cout << "cannot reach destination\n";
continue;
}
cout << "maximum height = " << Height << "\n";
cout << "length of shortest route = " << path << "\n";
}
return ;
}
Day4 - I - Trucking HDU - 2962的更多相关文章
- hdu 2962 Trucking (二分+最短路Spfa)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...
- Trucking(HDU 2962 最短路+二分搜索)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2962 Trucking (最短路径)
Trucking Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU - 2962 Trucking SPFA+二分
Trucking A certain local trucking company would like to transport some goods on a cargo truck from o ...
- HDU 2962 Trucking
题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...
- UVALive 4223 / HDU 2962 spfa + 二分
Trucking Problem Description A certain local trucking company would like to transport some goods on ...
- Day4 - C - 六度分离 HDU - 1869
1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人 ...
- hdu 2962 最短路+二分
题意:最短路上有一条高度限制,给起点和最大高度,求满足高度最大情况下,最短路的距离 不明白为什么枚举所有高度就不对 #include<cstdio> #include<cstring ...
- hdu 2962 题解
题目 题意 给出一张图,每条道路有限高,给出车子的起点,终点,最高高度,问在保证高度尽可能高的情况下的最短路,如果不存在输出 $ cannot reach destination $ 跟前面 $ ...
随机推荐
- word2vec 构建中文词向量
词向量作为文本的基本结构——词的模型,以其优越的性能,受到自然语言处理领域研究人员的青睐.良好的词向量可以达到语义相近的词在词向量空间里聚集在一起,这对后续的文本分类,文本聚类等等操作提供了便利,本文 ...
- selenium webdriver 操作RadioButton
@Test public void testRadio() { WebDriver driver = ExplorerBase.IESetting(); try { Thread.sleep(500) ...
- MySQL(window10)加载配置文件的顺序
mysql加载配置的顺序为:(mysql --help中有详细的说明) C:\WINDOWS\my.ini C:\WINDOWS\my.cnf C:\my.ini C:\my.cnf D:***\my ...
- 并发编程之Event事件
Event事件 用来同步线程之间的状态. 举个例子: 你把一个任务丢到了子线程中,这个任务将异步执行.如何获取到这个任务的执行状态 解决方法: 如果是拿到执行结果 我们可以采用异步回调, 在这里我 ...
- Primecoin服务端更新--操作流程
Primecoin服务端更新流程: 一.下载更新文件primecoin_x.y.z_xx.zip到/servers目录下:这里是把:版本primecoin0161alpha1更新到:版本primec ...
- tomcat中servlet冲突问题
在启动tomcat以后,控制台发现“Offending class: javax/servlet/Servlet.class”信息: 信息: validateJarFile(E:\code\MyApp ...
- ABC154F - Many Many Paths
梦回高中,定义的f(i,j)为从(0,0)到(i,j)一共有多少条路可以选择,易知我们要做i+j次选择,其中有i次是选择x轴,剩下的是y轴,所以f(i,j)=C(i+j,i)=C(i+j,j),给你一 ...
- Python 之网络编程之进程总体概要
一: 进程的概念:(Process) 进程就是正在运行的程序,它是操作系统中,资源分配的最小单位. 资源分配:分配的是cpu和内存等物理资源 进程号是进程的唯一标识 同一个程序执行两次之后是两个进程 ...
- 143、Java内部类之访问方法中定义的参数或变量
01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; publi ...
- kubernetes 1.5.2 部署kube-dns 踩过的坑
看了kubernetes 权威指南 遇见了dns这一块.于是便按照书上的方式部署了一下. 书上使用的方式是:kube2sky+etcd+skydns的方式.按照书上的yaml写了一遍,发现无论如何都无 ...