Delay Constrained Maximum Capacity Path HDU
来源:互联网 发布:转行做网络运营 编辑:程序博客网 时间:2024/06/16 12:02
点击打开链接
题目要求 首先要按时到达 其次尽可能走最短路线
通过二分 看能否在以当前长度的边为最短边的情况下按时到达 若不能则下调 否则上调
因为一条路径中最短边越长 对这条路径中边的要求也就越高 某些费时更少的边就被排除了 可能导致无法按时到达
反之 超过时限的可能也就越小
#include <stdio.h>#include <vector>#include <queue>#include <algorithm>#define N 99999999using namespace std;struct node1{ int v; long long cap; int con;};struct node2{ friend bool operator < (node2 n1,node2 n2) { return n1.s>n2.s; } int id; int s;};vector <struct node1> edge[10001];long long len[50001];long long ans;int dis[10001],book[10001];int n,m,time,limit;void binsearch();int calculate();int main(){ struct node1 t; long long c; int cnt,i,j,a,b,d; scanf("%d",&cnt); while(cnt--) { scanf("%d%d%d",&n,&m,&time); for(i=1;i<=n;i++) { edge[i].clear(); } for(i=1;i<=m;i++) { scanf("%d%d%lld%d",&a,&b,&c,&d); t.v=b,t.cap=c,t.con=d; edge[a].push_back(t); t.v=a,t.cap=c,t.con=d; edge[b].push_back(t); len[i]=c; } sort(len+1,len+m+1); binsearch(); printf("%lld\n",ans); } return 0;}void binsearch(){ int l,mid,r; l=1,r=m,ans=len[l]; while(l<=r) { mid=(l+r)/2; limit=len[mid]; if(calculate()) { ans=len[mid]; l=mid+1; } else { r=mid-1; } } return;}int calculate(){ priority_queue <struct node2> que; struct node1 t; struct node2 cur,tem; int i,p; for(i=1;i<=n;i++) { dis[i]=N; book[i]=0; } dis[1]=0; tem.id=1; tem.s=0; que.push(tem); while(!que.empty()) { cur=que.top(); que.pop(); p=cur.id; if(book[p]==1) continue; book[p]=1; for(i=0;i<edge[p].size();i++) { t=edge[p][i]; if(t.cap>=limit&&book[t.v]==0&&dis[t.v]>dis[p]+t.con) { dis[t.v]=dis[p]+t.con; tem.id=t.v; tem.s=dis[t.v]; que.push(tem); } } } if(dis[n]<=time) return 1; else return 0;}
阅读全文
0 0
- hdu 1839 Delay Constrained Maximum Capacity Path
- hdu 1839 Delay Constrained Maximum Capacity Path
- hdu 1839:Delay Constrained Maximum Capacity Path
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU-1839-Delay Constrained Maximum Capacity Path
- Delay Constrained Maximum Capacity Path HDU
- Delay Constrained Maximum Capacity Path HDU
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+最短路)
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路
- HDU-1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- 【HDU】1839 Delay Constrained Maximum Capacity Path 二分+最短路
- hdu 1839 Delay Constrained Maximum Capacity Path 二分+ spfa
- HDU 1839 Delay Constrained Maximum Capacity Path 最短路+二分
- HDU 1839 Delay Constrained Maximum Capacity Path(最短路+二分)
- HDU 1839 Delay Constrained Maximum Capacity Path(二分+SPFA)
- java Calendar类(日历)
- hibernate注解扫描配置
- gogland配置说明
- Java-Collection
- 《三》STM32中断以及中断解析
- Delay Constrained Maximum Capacity Path HDU
- express+monogo实现ToDo Restful Api
- 多对多业务,数据库水平切分架构一次搞定(58沈剑)
- javaEE项目Multipartfile实现文件上传下载并解决上传与下载文件中文乱码的问题
- 百度之星寻找母串
- 关于tensorflow 用于线性回归及MNIST 数字识别中的一些思考及补充
- CyclicBarrier同时执行
- Java密码学
- java面试题,各大企业常见的java笔试题之二