查看题目

  最小化第K大值。    

  让我怀疑人生的一题目,我有这么笨?

  1. #include <cstdio>
  2. #include <queue>
  3. #include <cstring>
  4. #include <vector>
  5. #include <functional>
  6. using namespace std;
  7. #define maxv 1010
  8. #define maxl 1000000
  9. struct edge
  10. {
  11. int to, cost;
  12. edge(){}
  13. edge(int to, int cost) : to(to), cost(cost){}
  14. };
  15. typedef pair<int, int> P;
  16. vector<edge> G[maxv];
  17. int d[maxv];
  18. int V, E;
  19. int dij(int s, int x) {
  20. priority_queue<P, vector<P>, greater<P> > que;
  21. memset(d, 0X3f, V*sizeof(int));
  22. d[s] = ;
  23. que.push(P(, s));
  24. while (!que.empty()) {
  25. P p = que.top(); que.pop();
  26. int v = p.second;
  27. if (d[v] < p.first) continue;
  28. for (int i = ; i < G[v].size(); ++i)
  29. {
  30. edge e = G[v][i];
  31. int new_d = d[v] + (e.cost >= x ? : );
  32. if (d[e.to] > new_d)
  33. {
  34. d[e.to] = new_d;
  35. que.push(P(d[e.to], e.to));
  36. }
  37. }
  38. }
  39. return d[V-];
  40. }
  41. int main(void) {
  42. freopen("in.txt", "r", stdin);
  43. freopen("out.txt", "w", stdout);
  44. int K;
  45. scanf("%d%d%d", &V, &E, &K);
  46. for (int i = ; i < E; ++i) {
  47. int A, B, L;
  48. scanf("%d%d%d", &A, &B, &L);
  49. --A, --B;
  50. G[A].push_back(edge(B,L));
  51. G[B].push_back(edge(A,L));
  52. }
  53. int l = , u = maxl+;
  54. for (;(u-l) > ;) {
  55. int m = (u+l) >> ;
  56. if (dij(, m) > K) {
  57. l = m;
  58. } else {
  59. u = m;
  60. }
  61. }
  62. printf("%d\n", (l>maxl ? - : l));
  63. return ;
  64. }

POJ 3662 Telephone Lines(二分+最短路)的更多相关文章

  1. poj 3662 Telephone Lines(最短路+二分)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6973   Accepted: 2554 D ...

  2. POJ 3662 Telephone Lines (二分+Dijkstra: 最小化第k大的值)

    题意 Farmer John想从电话公司修一些电缆连接到他农场.已知N个电线杆编号为1,2,⋯N,其中1号已经连接电话公司,N号为农场,有P对电线杆可连接. 现给出P对电线杆距离Ai,Bi,Li表示A ...

  3. POJ 3662 Telephone Lines (二分+dijkstra)

    题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...

  4. (poj 3662) Telephone Lines 最短路+二分

    题目链接:http://poj.org/problem?id=3662 Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total ...

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

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

  6. poj 3662 Telephone Lines spfa算法灵活运用

    意甲冠军: 到n节点无向图,它要求从一个线1至n路径.你可以让他们在k无条,的最大值.如今要求花费的最小值. 思路: 这道题能够首先想到二分枚举路径上的最大值,我认为用spfa更简洁一些.spfa的本 ...

  7. poj 3662 Telephone Lines

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7115   Accepted: 2603 D ...

  8. POJ 3662 Telephone Lines (分层图)

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6785   Accepted: 2498 D ...

  9. poj 3662 Telephone Lines dijkstra+二分搜索

    Telephone Lines Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5696   Accepted: 2071 D ...

随机推荐

  1. python install

    Install all dependencies by pip install -r requirements.txt (Run this command from project root)

  2. java调用.net asmx / wcf

    一.先用asmx与wcf写二个.net web service: 1.1 asmx web服务:asmx-service.asmx.cs using System; using System.Coll ...

  3. grunt使用入门(zz)

    下面介绍grunt的基本使用方法,把前端项目中的对个js文件,合并到一起,并压缩. 注意,例子用的是grunt 0.4.5版本,低版本可能在配置上有所不同. 工具/原料 node 方法/步骤 首先用n ...

  4. Windbg调优Kafka.Client内存泄露

    从来没写过Blog,想想也是,工作十多年了,搞过N多的架构.技术,不与大家分享实在是可惜了.另外,从传统地ERP行业转到互联网,也遇到了很所前所未有的问题,原来知道有一些坑,但是不知道坑太多太深.借着 ...

  5. C++学习准则

    C++学习准则  1.把C++当成一门新的语言学习(和C没啥关系!真的): 2.看<Thinking In C++>,不要看<C++变成死相>(C++编程思想,翻译的非常差): ...

  6. Recommending branded products from social media -RecSys 2013-20160422

    1.Information publication:RecSys 2013 author:zhengyong zhang 2.What 是对上一篇论文的拓展:利用社交媒体中用户信息 对用户购买的类别排 ...

  7. jni的使用方法

    我们可以通过jni来调用c/c++程序,C/C++一般会被作为动态库的形式来供java程序调用 环境 操作系统:Centos6.7 java: openjdk7 依赖包:java7-devel(yum ...

  8. iOS10-- snapshotViewAfterScreenUpdates 失效

    如果snapshotViewAfterScreenUpdates失效, 用这个方法替代, 不过要自己创建ImageView 替代方式: - (UIImage *)imageFromView:(UIVi ...

  9. Java--笔记(2)

    11.根据操作系统中的定义:死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所站用不会释放的资源而处于的一种永久等待状态. 死锁的四个必要条件: 1)互斥条件(Mutual ...

  10. linux 设置日志编码

    打开linux的设置面板 在Appearance选项->Character encoding 设置为UTF-8