HDU 1839 Delay Constrained Maximum Capacity Path
2016-04-21 18:54
423 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1839
Total Submission(s): 1242 Accepted Submission(s): 387
[align=left]Problem Description[/align]Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with 1 corresponds to a mine from where some precious minerals are extracted. The vertex numbered with N corresponds to a minerals processing factory. Each edge has an associated travel time (in time units) and capacity (in units of minerals). It has been decided that the minerals which are extracted from the mine will be delivered to the factory using a single path. This path should have the highest capacity possible, in order to be able to transport simultaneously as many units of minerals as possible. The capacity of a path is equal to the smallest capacity of any of its edges. However, the minerals are very sensitive and, once extracted from the mine, they will start decomposing after T time units, unless they reach the factory within this time interval. Therefore, the total travel time of the chosen path (the sum of the travel times of its edges) should be less or equal to T.
[align=left]Input[/align]The first line of input contains an integer number X, representing the number of test cases to follow. The first line of each test case contains 3 integer numbers, separated by blanks: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and T (1 <= T <= 500.000). Each of the next M lines will contain four integer numbers each, separated by blanks: A, B, C and D, meaning that there is an edge between vertices A and B, having capacity C (1 <= C <= 2.000.000.000) and the travel time D (1 <= D <= 50.000). A and B are different integers between 1 and N. There will exist at most one edge between any two vertices.
[align=left]Output[/align]For each of the X test cases, in the order given in the input, print one line containing the highest capacity of a path from the mine to the factory, considering the travel time constraint. There will always exist at least one path between the mine and the factory obbeying the travel time constraint.
[align=left]Sample Input[/align]2
2 1 10
1 2 13 10
4 4 20
1 2 1000 15
2 4 999 6
1 3 100 15
3 4 99 4
[align=left]Sample Output[/align]13
99
[align=left]Author[/align]Mugurel Ionut Andreica
[align=left]Source[/align]Politehnica University of Bucharest Local Team Contest 2007
[align=left]Recommend[/align]lcy | We have carefully selected several similar problems for you: 4114 3986 1162 1841 4063 这道题的大意是:有n个点 m条路,给出n,m,T ,T为限制时间,然后给出m个A B C D ,A:起点 B:终点 C:运输能力 D:从A到B的时间。求从1到n的的一条路径使得总时间小于=T,且运输能力最大。解题思路:考虑到要求运输能力最大,且运输能力受到道路的限制,我们可以按道路的运输能力排序,然后进行枚举求最短时间看时间是否小于T,为了不超时,我们用二分。代码如下:#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
#define maxn 10005
#define maxm 50005
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
struct node
{
int v,w,next,cap;
}edge[2*maxm];
int n,m,T,limit;
int pre[maxn];
int vis[maxn];
int dist[maxn];
int cap[maxm];
void init()
{
memset(pre,-1,sizeof pre);
int Index=1;
int i;
int x,y,w;
for(i=1;i<=m;i++)///建图的过程
{
scanf("%d%d%d%d",&x,&y,&cap[i],&w);
edge[Index].v=y;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[x];///一条边就让他指向-1
pre[x]=Index++;
edge[Index].v=x;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[y];
pre[y]=Index++;
}
}
int spfa()
{
int start=1;
int end=n;
queue<int>q;
fill(dist+1,dist+maxn+1,INF);///初始化dist为INF
cle(vis);
dist[start]=0;
vis[start]=1;
q.push(start);
while(!q.empty())
{
int top=q.front();
q.pop();
vis[top]=0;///清为零
for(int j=pre[top];j!=-1;j=edge[j].next)
{
int e=edge[j].v;///边终点
if(edge[j].cap>=limit)///如果cap大于limit则进行判断。否则不更新
if(dist[e]>edge[j].w+dist[top])
{
dist[e]=edge[j].w+dist[top];
if(!vis[e])
{
q.push(e);
vis[e]=1;
}
}
}
}
return dist
;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>T;
init();
sort(cap+1,cap+1+m,cmp);
int low=1,high=m;
while(low<high)
{
int mid=(low+high)>>1;
limit=cap[mid];
int tmp=spfa();
if(tmp==INF||tmp>T)
low=mid+1;
else
high=mid;
}
cout<<cap[low]<<endl;
}
return 0;
}
!
Delay Constrained Maximum Capacity Path
Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1242 Accepted Submission(s): 387
[align=left]Problem Description[/align]Consider an undirected graph with N vertices, numbered from 1 to N, and M edges. The vertex numbered with 1 corresponds to a mine from where some precious minerals are extracted. The vertex numbered with N corresponds to a minerals processing factory. Each edge has an associated travel time (in time units) and capacity (in units of minerals). It has been decided that the minerals which are extracted from the mine will be delivered to the factory using a single path. This path should have the highest capacity possible, in order to be able to transport simultaneously as many units of minerals as possible. The capacity of a path is equal to the smallest capacity of any of its edges. However, the minerals are very sensitive and, once extracted from the mine, they will start decomposing after T time units, unless they reach the factory within this time interval. Therefore, the total travel time of the chosen path (the sum of the travel times of its edges) should be less or equal to T.
[align=left]Input[/align]The first line of input contains an integer number X, representing the number of test cases to follow. The first line of each test case contains 3 integer numbers, separated by blanks: N (2 <= N <= 10.000), M (1 <= M <= 50.000) and T (1 <= T <= 500.000). Each of the next M lines will contain four integer numbers each, separated by blanks: A, B, C and D, meaning that there is an edge between vertices A and B, having capacity C (1 <= C <= 2.000.000.000) and the travel time D (1 <= D <= 50.000). A and B are different integers between 1 and N. There will exist at most one edge between any two vertices.
[align=left]Output[/align]For each of the X test cases, in the order given in the input, print one line containing the highest capacity of a path from the mine to the factory, considering the travel time constraint. There will always exist at least one path between the mine and the factory obbeying the travel time constraint.
[align=left]Sample Input[/align]2
2 1 10
1 2 13 10
4 4 20
1 2 1000 15
2 4 999 6
1 3 100 15
3 4 99 4
[align=left]Sample Output[/align]13
99
[align=left]Author[/align]Mugurel Ionut Andreica
[align=left]Source[/align]Politehnica University of Bucharest Local Team Contest 2007
[align=left]Recommend[/align]lcy | We have carefully selected several similar problems for you: 4114 3986 1162 1841 4063 这道题的大意是:有n个点 m条路,给出n,m,T ,T为限制时间,然后给出m个A B C D ,A:起点 B:终点 C:运输能力 D:从A到B的时间。求从1到n的的一条路径使得总时间小于=T,且运输能力最大。解题思路:考虑到要求运输能力最大,且运输能力受到道路的限制,我们可以按道路的运输能力排序,然后进行枚举求最短时间看时间是否小于T,为了不超时,我们用二分。代码如下:#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
#define maxn 10005
#define maxm 50005
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
struct node
{
int v,w,next,cap;
}edge[2*maxm];
int n,m,T,limit;
int pre[maxn];
int vis[maxn];
int dist[maxn];
int cap[maxm];
void init()
{
memset(pre,-1,sizeof pre);
int Index=1;
int i;
int x,y,w;
for(i=1;i<=m;i++)///建图的过程
{
scanf("%d%d%d%d",&x,&y,&cap[i],&w);
edge[Index].v=y;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[x];///一条边就让他指向-1
pre[x]=Index++;
edge[Index].v=x;
edge[Index].w=w;
edge[Index].cap=cap[i];
edge[Index].next=pre[y];
pre[y]=Index++;
}
}
int spfa()
{
int start=1;
int end=n;
queue<int>q;
fill(dist+1,dist+maxn+1,INF);///初始化dist为INF
cle(vis);
dist[start]=0;
vis[start]=1;
q.push(start);
while(!q.empty())
{
int top=q.front();
q.pop();
vis[top]=0;///清为零
for(int j=pre[top];j!=-1;j=edge[j].next)
{
int e=edge[j].v;///边终点
if(edge[j].cap>=limit)///如果cap大于limit则进行判断。否则不更新
if(dist[e]>edge[j].w+dist[top])
{
dist[e]=edge[j].w+dist[top];
if(!vis[e])
{
q.push(e);
vis[e]=1;
}
}
}
}
return dist
;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
cin>>t;
while(t--)
{
cin>>n>>m>>T;
init();
sort(cap+1,cap+1+m,cmp);
int low=1,high=m;
while(low<high)
{
int mid=(low+high)>>1;
limit=cap[mid];
int tmp=spfa();
if(tmp==INF||tmp>T)
low=mid+1;
else
high=mid;
}
cout<<cap[low]<<endl;
}
return 0;
}
!
相关文章推荐
- HDU1789 Doing Homework again(贪心)
- 爬楼梯的问题Climbing Stairs
- 十、责任链模式Chain of Responsibility(行为型模式)
- http://blog.csdn.net/holybin/article/details/46955185
- 服务器端主动关闭连接, 产生的TIME_WAIT状态为什么会占用服务端大量端口?
- HoloLens开发手记-硬件细节 Hardware Detail
- git修改提交的用户名和Email
- 03-树3 Tree Traversals Again
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- 正确使用Block避免Cycle Retain和Crash
- lightoj 1076 - Get the Containers 【二分 + 贪心】
- Failed to read artifact descriptor进行安装maven项目出错
- AI编辑SVG格式的相关问题
- paip.自适应网页设计 跟 响应式 设计的区别跟原理and实践总结
- 图解RAID 0, RAID 1, RAID 5, RAID 10
- go gomail
- R语言中的正则表达式(转载:http://blog.csdn.net/duqi_yc/article/details/9817243)
- kaidi中 install cuda
- stl map用法和make_pair函数
- 关于解决 Failed to prepare partial IU: