Task Schedule HDU
来源:互联网 发布:java webservice demo 编辑:程序博客网 时间:2024/05/18 01:44
Our geometry princess XMM has stoped her study in computational geometry to concentrate on her newly opened factory. Her factory has introduced M new machines in order to process the coming N tasks. For the i-th task, the factory has to start processing it at or after day Si, process it for Pi days, and finish the task before or at day Ei. A machine can only work on one task at a time, and each task can be processed by at most one machine at a time. However, a task can be interrupted and processed on different machines on different days.
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
Input
On the first line comes an integer T(T<=20), indicating the number of test cases.
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
For each test case, print “Case x: ” first, where x is the case number. If there exists a feasible schedule to finish all the tasks, print “Yes”, otherwise print “No”.
Print a blank line after each test case.
Sample Input
2
4 3
1 3 5
1 1 4
2 3 7
3 5 9
2 2
2 1 3
1 2 2
Sample Output
Case 1: Yes
Case 2: Yes
用ek算法无限t,学了dinic好多了
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<queue>#define INF 0x3f3f3f3fusing namespace std;const int maxn=1505;const int maxx=520010;int edge;int to[maxx],flow[maxx],nex[maxx];int head[maxn];void addEdge(int v,int u,int cap){ to[edge]=u,flow[edge]=cap,nex[edge]=head[v],head[v]=edge++; to[edge]=v,flow[edge]=0,nex[edge]=head[u],head[u]=edge++;}int vis[maxn];int pre[maxn];bool bfs(int s,int e){ queue<int> que; pre[s]=-1; memset(vis,-1,sizeof(vis)); que.push(s); vis[s]=0; while(!que.empty()) { int u=que.front(); que.pop(); for(int i=head[u];~i;i=nex[i]) { int v=to[i]; if(vis[v]==-1&&flow[i]) { vis[v]=vis[u]+1; if(v==e) return true; que.push(v); } } } return false;}int dfs(int s,int t,int f){ if(s==t||!f) return f; int r=0; for(int i=head[s];~i;i=nex[i]) { int v=to[i]; if(vis[v]==vis[s]+1&&flow[i]) { int d=dfs(v,t,min(f,flow[i])); if(d>0) { flow[i]-=d; flow[i^1]+=d; r+=d; f-=d; if(!f) break; } } } if(!r) vis[s]=INF; return r;}int maxFlow(int s ,int e){ int ans=0; while(bfs(s,e)) ans+=dfs(s,e,INF); return ans;}void init(){ memset(head,-1,sizeof(head)); edge=0;}int main(){ int t; scanf("%d",&t); int n,m; int p,s,e; int top=-1; int cal=1; while(t--) { scanf("%d%d",&n,&m); int sum=0; init(); for(int i=1;i<=n;i++) { scanf("%d%d%d",&p,&s,&e); sum+=p; top=max(top,e); addEdge(0,i,p); for(int j=s;j<=e;j++) addEdge(i,n+j,1); } for(int i=1;i<=top;i++) addEdge(n+i,top+n+1,m); if(sum==maxFlow(0,top+n+1)) printf("Case %d: Yes\n\n",cal++); else printf("Case %d: No\n\n",cal++); } return 0;}
- hdu 3572 Task Schedule
- HDU 3572 Task Schedule
- hdu 3572 Task Schedule
- HDU 4907 Task schedule
- hdu 4907 Task schedule
- hdu 4907 Task schedule
- HDU 4907 Task schedule
- hdu 4007 Task schedule
- hdu 4907 Task schedule
- HDU 4907 Task schedule
- HDU-4907 Task schedule
- HDU 3572 Task Schedule
- hdu 3572 Task Schedule
- hdu 3572 Task Schedule
- HDU 4907 Task schedule
- HDU 3572 Task Schedule
- HDU 3572 Task Schedule
- 【HDU】 3572 Task Schedule
- 俄罗斯最新航空技术大放异彩 ----无人机、无人飞艇、着地轮电力驱动装置等现莫斯科航展
- Cassia HUB京东众筹受热捧 用户为人性科技买单
- 互联网金融产品体验不佳?你可能还没用过荷包
- 内容为王!应用市场玩法升级全面竞争
- 更大更旗舰 3GB运存版最美手机vivo X5Pro上市
- Task Schedule HDU
- CentOS安装MySQL时提示"/usr/bin/perl is needed by MySQL-server-..."
- 救援模式<修改root密码>
- 423.Reconstruct Original Digits from English
- Firefly开源硬件:为极致而生的开源平台!
- poj 3613 floyd
- ZUI初体验:免Root卸载内置软件
- mysql触发器
- 换机不换卡 双卡双待三网通吃手机推荐