题意:最短路上有一条高度限制,给起点和最大高度,求满足高度最大情况下,最短路的距离

不明白为什么枚举所有高度就不对

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. const int maxint=;
  5. int c[][][],dist[],H[];
  6. using namespace std;
  7. int n,line;
  8. int i,j,k;
  9. int st,ed,mid;
  10. int t=;
  11. int path[];
  12. int visit[];
  13. bool dijkstra()
  14. {
  15. bool s[];
  16. for(int i=;i<=n;i++)
  17. {
  18. s[i]=;
  19. if(c[st][i][]>=mid)
  20. dist[i]=c[st][i][];
  21. else dist[i]=maxint;
  22. path[i]=st;
  23. }
  24. s[st]=;
  25. for(int i=;i<n;i++)
  26. {
  27. int temp=maxint;
  28. int u=st;
  29. for(int j=;j<=n;j++)
  30. if(!s[j]&&temp>dist[j]&&c[path[j]][j][]>=mid)
  31. {
  32. temp=dist[j];
  33. u=j;
  34. }
  35. if(temp==maxint) break;
  36. s[u]=;
  37. if(u==ed) return true;
  38. for(int j=;j<=n;j++)
  39. if(!s[j]&&c[u][j][]!=maxint&&c[u][j][]>=mid)
  40. if(dist[j]>dist[u]+c[u][j][])
  41. {
  42. dist[j]=dist[u]+c[u][j][];
  43. path[j]=u;
  44. }
  45. }
  46. return false;
  47. }
  48. int main()
  49. {
  50. #ifndef ONLINE_JUDGE
  51. freopen("1.in","r",stdin);
  52. #endif
  53. while(scanf("%d%d",&n,&line)!=EOF&&n&&line)
  54. {
  55. int tot=;
  56. memset(H,,sizeof(H));
  57. H[]=;
  58. if(t) printf("\n");
  59. printf("Case %d:\n",++t);
  60. for(i=;i<=n;i++)
  61. for(j=;j<=n;j++)
  62. {
  63. c[i][j][]=(i==j?:maxint);
  64. c[i][j][]=-;
  65. }
  66. for(i=;i<=line;i++)
  67. {
  68. int p,q,len,h;
  69. scanf("%d%d%d%d",&q,&p,&h,&len);
  70. if(h==-)
  71. {
  72. c[p][q][]=c[q][p][]=maxint;
  73. c[p][q][]=c[q][p][]=len;
  74. continue;
  75. }
  76. if(c[p][q][]<h)
  77. {
  78. c[p][q][]=c[q][p][]=h;
  79. c[p][q][]=c[q][p][]=len;
  80. }
  81. }
  82. int tall;
  83. scanf("%d%d%d",&st,&ed,&tall);
  84. /*if(st==ed)
  85. {
  86. printf("maximum height = %d\n",tall);
  87. printf("length of shortest route = 0\n");
  88. continue;
  89. }*/
  90. /*H[tot++]=tall;
  91. sort(H,H+tot);
  92. int ans=0;
  93. bool flag=0;
  94. for(i=tot-1;i>=0;i--)
  95. {
  96. if(H[i]>tall) continue;
  97. mid=H[i];
  98. if(dijkstra())
  99. {
  100. flag=1;
  101. ans=dist[ed];
  102. break;
  103. }
  104. }*/
  105. int first=;
  106. int ans;
  107. mid=(first+tall)>>;
  108. while(first<=tall)
  109. {
  110. if(dijkstra())
  111. {
  112. ans=dist[ed];
  113. first=mid+;
  114. }
  115. else
  116. tall=mid-;
  117. mid=(first+tall)>>;
  118. }
  119. if(tall==) printf("cannot reach destination\n");
  120. else
  121. {
  122. printf("maximum height = %d\n",tall);
  123. printf("length of shortest route = %d\n",ans);
  124. }
  125. }
  126. return ;
  127. }

hdu 2962 最短路+二分的更多相关文章

  1. HDU - 2962 Trucking SPFA+二分

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

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

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

  3. ACM: HDU 2544 最短路-Dijkstra算法

    HDU 2544最短路 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descrip ...

  4. UESTC 30 &&HDU 2544最短路【Floyd求解裸题】

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. POJ 3662 Telephone Lines【Dijkstra最短路+二分求解】

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7214   Accepted: 2638 D ...

  6. hdu 5521 最短路

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  7. poj 2391 Ombrophobic Bovines 最短路 二分 最大流 拆点

    题目链接 题意 有\(n\)个牛棚,每个牛棚初始有\(a_i\)头牛,最后能容纳\(b_i\)头牛.有\(m\)条道路,边权为走这段路所需花费的时间.问最少需要多少时间能让所有的牛都有牛棚可待? 思路 ...

  8. Luogu P1462 通往奥格瑞玛的道路(最短路+二分)

    P1462 通往奥格瑞玛的道路 题面 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己 ...

  9. HDU - 2544最短路 (dijkstra算法)

    HDU - 2544最短路 Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以 ...

随机推荐

  1. Memcache 内存分配策略和性能(使用)状态检查【转】

    前言: 一直在使用Memcache,但是对其内部的问题,如它内存是怎么样被使用的,使用一段时间后想看看一些状态怎么样?一直都不清楚,查了又忘记,现在整理出该篇文章,方便自己查阅.本文不涉及安装.操作. ...

  2. 使用postman做接口测试(一)

    参考大神的总结:https://www.cnblogs.com/Skyyj/p/6856728.html 一,先了解一下基础知识,虽然工作中没什么卵用,但背会了,可以显摆自己很专业的样子,以下内容来自 ...

  3. 【本地服务器】用nodejs搭建最简单、轻量化的http server

    1. 引言 前端程序猿主要关注的是页面,你可能根本就用不到.net,java,php等后台语言. 但是你制作出来的网页总要运行.总要测试吧?——那就免不了用到http server.我先前都是用vis ...

  4. python基础--json,pickle和shelve模块

    一.JSON &pickle 用于序列化的两个模块 json,用于字符串 和 python数据类型间进行转换  字符串必须是双引号,不能是单引号 pickle,用于python特有的类型 和 ...

  5. python基础-类的起源

    Python中一切事物都是对象. class Foo(object): def __init__(self,name): self.name = name f = Foo("alex&quo ...

  6. Hadoop(二):MapReduce程序(Java)

    Java版本程序开发过程主要包含三个步骤,一是map.reduce程序开发:第二是将程序编译成JAR包:第三使用Hadoop jar命令进行任务提交. 下面拿一个具体的例子进行说明,一个简单的词频统计 ...

  7. CF529B 【Group Photo 2 (online mirror version)】

    贪心枚举最后方案中最大的h,设为maxh若某个人i的wi与hi均大于maxh,则此方案不可行若某个人恰有一个属性大于maxh,则可确定他是否换属性剩下的人按wi-hi从大到小排序后贪心选择O(nlog ...

  8. python图片处理和matlab图片处理的区别

    作者:波布兰链接:https://www.zhihu.com/question/28218420/answer/39904627来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...

  9. (五)动态SQL

    第一节:if条件 第二节:choose,when和otherwise条件 第三节:where条件 1.自动加上where: 2.如果where子句以and或者or开头,则自动删除第一个and或者or: ...

  10. Tango ROS Streamer

    谁想要在Android平台上编写机器人应用,或者谁希望扩展其与室内定位和3D感知新的传感器的机器人开发,Intermodalics创建的ROS Streamer应用的Tango. 这个Android应 ...