POJ 3662 Telephone Lines(二分+最短路)
最小化第K大值。
让我怀疑人生的一题目,我有这么笨?
- #include <cstdio>
- #include <queue>
- #include <cstring>
- #include <vector>
- #include <functional>
- using namespace std;
- #define maxv 1010
- #define maxl 1000000
- struct edge
- {
- int to, cost;
- edge(){}
- edge(int to, int cost) : to(to), cost(cost){}
- };
- typedef pair<int, int> P;
- vector<edge> G[maxv];
- int d[maxv];
- int V, E;
- int dij(int s, int x) {
- priority_queue<P, vector<P>, greater<P> > que;
- memset(d, 0X3f, V*sizeof(int));
- d[s] = ;
- que.push(P(, s));
- while (!que.empty()) {
- P p = que.top(); que.pop();
- int v = p.second;
- if (d[v] < p.first) continue;
- for (int i = ; i < G[v].size(); ++i)
- {
- edge e = G[v][i];
- int new_d = d[v] + (e.cost >= x ? : );
- if (d[e.to] > new_d)
- {
- d[e.to] = new_d;
- que.push(P(d[e.to], e.to));
- }
- }
- }
- return d[V-];
- }
- int main(void) {
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- int K;
- scanf("%d%d%d", &V, &E, &K);
- for (int i = ; i < E; ++i) {
- int A, B, L;
- scanf("%d%d%d", &A, &B, &L);
- --A, --B;
- G[A].push_back(edge(B,L));
- G[B].push_back(edge(A,L));
- }
- int l = , u = maxl+;
- for (;(u-l) > ;) {
- int m = (u+l) >> ;
- if (dij(, m) > K) {
- l = m;
- } else {
- u = m;
- }
- }
- printf("%d\n", (l>maxl ? - : l));
- return ;
- }
POJ 3662 Telephone Lines(二分+最短路)的更多相关文章
- poj 3662 Telephone Lines(最短路+二分)
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6973 Accepted: 2554 D ...
- POJ 3662 Telephone Lines (二分+Dijkstra: 最小化第k大的值)
题意 Farmer John想从电话公司修一些电缆连接到他农场.已知N个电线杆编号为1,2,⋯N,其中1号已经连接电话公司,N号为农场,有P对电线杆可连接. 现给出P对电线杆距离Ai,Bi,Li表示A ...
- POJ 3662 Telephone Lines (二分+dijkstra)
题意: 多年以后,笨笨长大了,成为了电话线布置师.由于地震使得某市的电话线全部损坏,笨笨是负责接到震中市的负责人. 该市周围分布着N(1<=N<=1000)根据1……n顺序编号的废弃的电话 ...
- (poj 3662) Telephone Lines 最短路+二分
题目链接:http://poj.org/problem?id=3662 Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total ...
- POJ 3662 Telephone Lines【Dijkstra最短路+二分求解】
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7214 Accepted: 2638 D ...
- poj 3662 Telephone Lines spfa算法灵活运用
意甲冠军: 到n节点无向图,它要求从一个线1至n路径.你可以让他们在k无条,的最大值.如今要求花费的最小值. 思路: 这道题能够首先想到二分枚举路径上的最大值,我认为用spfa更简洁一些.spfa的本 ...
- poj 3662 Telephone Lines
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7115 Accepted: 2603 D ...
- POJ 3662 Telephone Lines (分层图)
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6785 Accepted: 2498 D ...
- poj 3662 Telephone Lines dijkstra+二分搜索
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5696 Accepted: 2071 D ...
随机推荐
- python install
Install all dependencies by pip install -r requirements.txt (Run this command from project root)
- java调用.net asmx / wcf
一.先用asmx与wcf写二个.net web service: 1.1 asmx web服务:asmx-service.asmx.cs using System; using System.Coll ...
- grunt使用入门(zz)
下面介绍grunt的基本使用方法,把前端项目中的对个js文件,合并到一起,并压缩. 注意,例子用的是grunt 0.4.5版本,低版本可能在配置上有所不同. 工具/原料 node 方法/步骤 首先用n ...
- Windbg调优Kafka.Client内存泄露
从来没写过Blog,想想也是,工作十多年了,搞过N多的架构.技术,不与大家分享实在是可惜了.另外,从传统地ERP行业转到互联网,也遇到了很所前所未有的问题,原来知道有一些坑,但是不知道坑太多太深.借着 ...
- C++学习准则
C++学习准则 1.把C++当成一门新的语言学习(和C没啥关系!真的): 2.看<Thinking In C++>,不要看<C++变成死相>(C++编程思想,翻译的非常差): ...
- Recommending branded products from social media -RecSys 2013-20160422
1.Information publication:RecSys 2013 author:zhengyong zhang 2.What 是对上一篇论文的拓展:利用社交媒体中用户信息 对用户购买的类别排 ...
- jni的使用方法
我们可以通过jni来调用c/c++程序,C/C++一般会被作为动态库的形式来供java程序调用 环境 操作系统:Centos6.7 java: openjdk7 依赖包:java7-devel(yum ...
- iOS10-- snapshotViewAfterScreenUpdates 失效
如果snapshotViewAfterScreenUpdates失效, 用这个方法替代, 不过要自己创建ImageView 替代方式: - (UIImage *)imageFromView:(UIVi ...
- Java--笔记(2)
11.根据操作系统中的定义:死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所站用不会释放的资源而处于的一种永久等待状态. 死锁的四个必要条件: 1)互斥条件(Mutual ...
- linux 设置日志编码
打开linux的设置面板 在Appearance选项->Character encoding 设置为UTF-8