HDU 3572 Task Schedule (Max Stream)

Source: Internet
Author: User

HDU 3572 Task Schedule

Description
Our geometry Princess XMM have stoped her study in computational geometry to concentrate on her newly opened factory. Her factory had introduced M new machines in order to process the coming N tasks. For the i-th task, the factory have to start processing it on or after day Si, process it for Pi days, and finish the task Before or at day Ei. A machine can have work on one task at a time, and each task can be processed by at a time. However, a task can is interrupted and processed on different machines on different days.
Now she wonders whether he had a feasible schedule to finish all the tasks in time. She turns to the help.

Input
On the first line comes an integer T (t<=20), indicating the number of test cases.

You are given-N (n<=500) and M (m<=200) on the first line of all test case. Then on each of next N lines is three integers Pi, si and Ei (1<=pi, Si, ei<=500), which has the meaning described In the description. It is guaranteed, this in a feasible schedule every task, can be finished would be do 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

Topic: Give the number of tasks, and the number of machines. Each task consists of three messages: the time, start time, and end time that a machine needs to process. Ask if you can finish all the characters within the time frame of each task. Problem-solving ideas: Completely no idea, think this should be greedy topic. Later went to see the puzzle .... Set a super source point to All tasks, and the capacity is the time that the task needs to be processed. Then each task is connected to their corresponding time, for example a task time limit from 2 to 4, then the task node, the 2 3 4 time node, the capacity is 1. Then all the time nodes, connected to the super sink point, capacity for the number of machines. Quite ingenious, but I can't think of ...
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>using namespace STD;Const intINF =0x3f3f3f3f;Const intN =2500;Const intM =400005;Const intFIN = -;typedef Long LongllintN, M, s, t, sum;intEC, Head[n], first[n], que[n], lev[n];intNEXT[M], to[m], v[m];voidInit () {sum =0; EC =0;memset(First,-1,sizeof(first)); s =0, t = FIN;}voidAddedge (intAintBintc) {To[ec] = b;    V[EC] = c;    NEXT[EC] = First[a];    First[a] = ec++;    TO[EC] = A; V[EC] =0;    NEXT[EC] = first[b]; FIRST[B] = ec++;}intBFS () {intKid, now, F =0, r =1Imemset(Lev,0,sizeof(Lev)); que[0] = s, lev[s] =1; while(F < R) {now = que[f++]; for(i = First[now]; I! =-1; i = Next[i]) {kid = To[i];if(!lev[kid] && v[i]) {Lev[kid] = Lev[now] +1;if(Kid = = t)return 1;            que[r++] = kid; }        }    }return 0;}intDFS (intNowintSUM) {intKid, flow, RT =0;if(now = = t)returnSum for(inti = Head[now]; I! =-1&& RT < sum;          i = Next[i]) {Head[now] = i; Kid = To[i];if(Lev[kid] = = Lev[now] +1&& V[i]) {flow = DFS (Kid, Min (Sum-rt, v[i]));if(flow)                {V[i]-= flow; v[i^1] + = flow;            RT + = flow; }ElseLev[kid] =-1; }               }returnRT;}intDinic () {intAns =0; while(BFS ()) { for(inti =0; I <= t;        i++) {Head[i] = First[i];    } ans + = DFS (s, INF); }returnAns;}voidInput () {intMin = INF, Max =0;scanf("%d%d", &n, &m);intA, B, C; for(inti =1; I <= N; i++) {scanf(" %d%d%d", &a, &b, &c);        sum + = A; Addedge (S, I, a); for(intj = b; J <= C; J + +) {Addedge (i, j + N,1); }if(c < b) Swap (c, b);if(Min > B) Min = b;if(Max < C)    Max = C; } for(inti = Min; I <= Max;       i++) {Addedge (i + N, T, M); }}intMain () {intT, Case =1;scanf("%d", &t); while(t--) {printf("Case%d:", case++);        Init (); Input ();if(Dinic () = = SUM)printf("yes\n");Else printf("no\n");puts(""); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission can also be reproduced, but to indicate the source oh.

Hdu 3572 Task Schedule (Max Stream)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.