解题报告:hdu 3572 Task Schedule(当前弧优化Dinic算法)
Problem Description
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
Input
You are given two integer N(N<=500) and M(M<=200) on the first line of each test case. Then on each of next N lines are three integers Pi, Si and Ei (1<=Pi, Si, Ei<=500), which have the meaning described in the description. It is guaranteed that in a feasible schedule every task that can be finished will be done before or at its end day.
Output
Print a blank line after each test case.
Sample Input
Sample Output
- #include<bits/stdc++.h>
- using namespace std;
- const int INF=0x3f3f3f3f;
- const int maxn=;
- struct edge{ int to,cap;size_t rev;
- edge(int _to, int _cap, size_t _rev):to(_to),cap(_cap),rev(_rev){}
- };
- int T,n,m,p,s,e,tot,level[maxn];queue<int> que;vector<edge> G[maxn];size_t curfir[maxn];//当前弧数组
- void add_edge(int from,int to,int cap){
- G[from].push_back(edge(to,cap,G[to].size()));
- G[to].push_back(edge(from,,G[from].size()-));
- }
- bool bfs(int s,int t){
- memset(level,-,sizeof(level));
- while(!que.empty())que.pop();
- level[s]=;
- que.push(s);
- while(!que.empty()){
- int v=que.front();que.pop();
- for(size_t i=;i<G[v].size();++i){
- edge &e=G[v][i];
- if(e.cap>&&level[e.to]<){
- level[e.to]=level[v]+;
- que.push(e.to);
- }
- }
- }
- return level[t]<?false:true;
- }
- int dfs(int v,int t,int f){
- if(v==t)return f;
- for(size_t &i=curfir[v];i<G[v].size();++i){//从v的第curfir[v]条边开始,采用引用的方法,同时改变本身的值
- //因为节点v的第0~curfir[v]-1条边已达到满流了,所以无需重新遍历--->核心优化
- edge &e=G[v][i];
- if(e.cap>&&(level[v]+==level[e.to])){
- int d=dfs(e.to,t,min(f,e.cap));
- if(d>){
- e.cap-=d;
- G[e.to][e.rev].cap+=d;
- return d;
- }
- }
- }
- return ;
- }
- int max_flow(int s,int t){
- int f,flow=;
- while(bfs(s,t)){
- memset(curfir,,sizeof(curfir));//重新将图分层之后就清空数组,从第0条边开始遍历
- while((f=dfs(s,t,INF))>)flow+=f;
- }
- return flow;
- }
- int main(){
- while(~scanf("%d",&T)){
- for(int cas=;cas<=T;++cas){
- scanf("%d%d",&n,&m);tot=;
- for(int i=;i<maxn;++i)G[i].clear();
- for(int i=;i<=;++i)add_edge(+i,,m);
- for(int i=;i<=n;++i){
- scanf("%d%d%d",&p,&s,&e);
- add_edge(,i,p);tot+=p;//tot为总时间
- for(int j=s;j<=e;++j)add_edge(i,+j,);
- }
- printf("Case %d: %s\n\n",cas,max_flow(,)==tot?"Yes":"No");
- }
- }
- return ;
- }
解题报告:hdu 3572 Task Schedule(当前弧优化Dinic算法)的更多相关文章
- hdu 3572 Task Schedule (dinic算法)
pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 3572 Task Schedule(拆点+最大流dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- hdu 3572 Task Schedule 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...
- HDU 3572 Task Schedule (最大流)
C - Task Schedule Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 3572 Task Schedule
Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...
- hdu 3572 Task Schedule (Dinic模板)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
- hdu 3572 Task Schedule(最大流&&建图经典&&dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 3572 Task Schedule(ISAP模板&&最大流问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3572 题意:m台机器.须要做n个任务. 第i个任务.你须要使用机器Pi天,且这个任务要在[Si , ...
- 图论--网络流--最大流 HDU 3572 Task Schedule(限流建图,超级源汇)
Problem Description Our geometry princess XMM has stoped her study in computational geometry to conc ...
随机推荐
- javascript常用事件及方法
1.获取鼠标坐标,考虑滚动条拖动 var e = event || window.event; var scrollX = document.documentElement.scrollLeft || ...
- javascript if(xx)
js判断某个值知否存在或者为空,可以直接用if(xx)过滤. <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- ReactMotion Demo8 分析
链接 首先通过spring函数Motion的style参数, 传入Motion Component, 计算style的过程: const style = lastPressed === i & ...
- java24点算法
输入任意的四个数,求出所有能得到二十四点的算式,不过我是菜鸟,可能性能方面不好,希望各位多多指教1. [代码][Java]代码 import java.util.ArrayList;impo ...
- 一步一步学Silverlight 2系列(26):基本图形
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- Ural 1109 Conference(最小路径覆盖数)
题意:A国家有M个代表,B国有N个代表,其中有K对代表可以进行谈判(一个是A国的,一个是B国的),并且每一个代表至少被包含在其中一对中(也就是说,每个人可以至少找到另外一个人谈判),每一对谈判需要一对 ...
- select下拉带图片-模拟下拉
<style> /*下拉列表*/ ul,dl,ol,li {list-style: none;} .dropdown { float: right; position: relative; ...
- Flask app.config 的配置
原理如下: image.png 1.通过调用自定义config.py文件中config字典,可以得到一个类, 这个类里面定义的都是类变量,这些变量就是自定义的一些配置项. 如下config.py ...
- c/c++内存机制(一)(原)
一:C语言中的内存机制 在C语言中,内存主要分为如下5个存储区: (1)栈(Stack):位于函数内的局部变量(包括函数实参),由编译器负责分配释放,函数结束,栈变量失效. (2)堆(Heap):由程 ...
- 【转】Intellij idea 的maven项目如何通过maven自动下载jar包
原文地址: https://blog.csdn.net/machao0903/article/details/73368909 maven项目自动加载jar包 所需工具如下: Intellij IDE ...