A certain local trucking company would like to transport some goods on a cargo truck from one place to another. It is desirable to transport as much goods as possible each trip. Unfortunately, one cannot always use the roads in the shortest route: some roads may have obstacles (e.g. bridge overpass, tunnels) which limit heights of the goods transported. Therefore, the company would like to transport as much as possible each trip, and then choose the shortest route that can be used to transport that amount.

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的更多相关文章

  1. hdu 2962 Trucking (二分+最短路Spfa)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2962 Trucking Time Limit: 20000/10000 MS (Java/Others ...

  2. Trucking(HDU 2962 最短路+二分搜索)

    Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. hdu 2962 Trucking (最短路径)

    Trucking Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU - 2962 Trucking SPFA+二分

    Trucking A certain local trucking company would like to transport some goods on a cargo truck from o ...

  5. HDU 2962 Trucking

    题目大意:给定无向图,每一条路上都有限重,求能到达目的地的最大限重,同时算出其最短路. 题解:由于有限重,所以二分检索,将二分的值代入最短路中,不断保存和更新即可. #include <cstd ...

  6. UVALive 4223 / HDU 2962 spfa + 二分

    Trucking Problem Description A certain local trucking company would like to transport some goods on ...

  7. Day4 - C - 六度分离 HDU - 1869

    1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人 ...

  8. hdu 2962 最短路+二分

    题意:最短路上有一条高度限制,给起点和最大高度,求满足高度最大情况下,最短路的距离 不明白为什么枚举所有高度就不对 #include<cstdio> #include<cstring ...

  9. hdu 2962 题解

    题目 题意 给出一张图,每条道路有限高,给出车子的起点,终点,最高高度,问在保证高度尽可能高的情况下的最短路,如果不存在输出 $ cannot  reach  destination $ 跟前面 $ ...

随机推荐

  1. 变量的注释(python3.6以后的功能)

    有时候导入模块,然后使用这个变量的时候,却没点出后面的智能提示.用以下方法可以解决:https://www.cnblogs.com/xieqiankun/p/type_hints_in_python3 ...

  2. MySQL之关系

    目录 关系 多对多的关系,如何通过mysql来表示 一对一关系 关系 多对多的关系,如何通过mysql来表示 站在老师的角度 一个老师可以教多个学生, 一个老师也可以教一个学生. 站在学生的角度 一个 ...

  3. Django中defer和only区别

    defer('id', 'name'):取出对象,字段除了id和name都有 only('id', 'name'):取出对象, 只有id和name ret=models.Author.objects. ...

  4. Python学习第十九课——类的装饰器

    类的装饰器 # def deco(func): # print('==========') # return func # # # @deco #test=deco(test) # # def tes ...

  5. HDU 5564:Clarke and digits 收获颇多的矩阵快速幂 + 前缀和

    Clarke and digits  Accepts: 16  Submissions: 29  Time Limit: 5000/3000 MS (Java/Others)  Memory Limi ...

  6. Excel使用小技巧

    1.Excel随机设置单元格的内容为整数0或1: 在单元格中写公式:  =ROUND(RAND(),0) 2.设置某个单元格的值为1或0,根据其他3个单元格的值为0或1来确定: 在该单元格中写公式: ...

  7. 从Uber司机只是合同工看,零工经济将受沉重打击?

    Uber自诞生以来,就始终处于漩涡之中--与当地的同类平台斗.创始人出现负面新闻.司机不断抗议--而就在近日"流血上市"后,Uber也没能迎来好时光.反而是股价不断下跌,市值疯狂蒸 ...

  8. 浅谈区块链和p2p网络

    最近对区块链产生了兴趣就去了解了一下,分享一下.... 首先要先了解一下什么叫做区块链: 区块链:简单来说就是一种基于分布式数据存储.点对点传输.共识机制.加密算法等计算机技术的新型应用模式. 相信说 ...

  9. jsp页面展示更加商品的分类,控制商品的显示

    我的大概思路是这样的,第一后果获取所有的商品分类 保存在list集合里面,第二从后台获取所有的商品 第三在JSP页面遍历商品分类集合放在页面的左边,然后jsp页面商品详细信息这块,也得先遍历商品分类, ...

  10. redhat 7.6 查看硬件负载命令

    1.  命令 查看CPU负载 命令1:uptime 命令2:cat  /proc/loadavg 查看CPU信息:cat  /proc/cpuinfo load average:表示平均1分钟内运行的 ...