HDU3572 Task Schedule "Max Stream"

Source: Internet
Author: User
Tags cas

Task ScheduleTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 4003 Accepted Submission (s): 1347

Problem Descriptionour Geometry Princess XMM has stoped she study in computational geometry to concentrate on her newly op Ened 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.

Inputon 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.

Outputfor 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
24 31 3 5 1 1 42 3 73 5 92 22 1 31 2 2

Sample Output
Case 1:yes Case   2:yes

Authorallenlowesy
Source2010 acm-icpc multi-university Training Contest (--host by UESTC)Test Instructions: There are n machines, m tasks, each task need pi days time, start date to the date of the call Si to EI. Can only be processed on one machine at a time, can be moved to another machine, ask whether can complete the task on schedule. problem: The key in the composition, set a source point to each task has an edge, capacity for the task of the number of days, each task to the legal processing date of each day plus an edge, capacity of 1, that is, the daily work amount of 1. Then each number of days to the meeting point to add an edge, the capacity of the number of machines N. Represents the maximum amount of processing per day.

218ms

#include <stdio.h> #include <string.h> #define MAXN 1200#define MAXM 700000#define inf 0x3f3f3f3fint head[ MAXN], N, m, id; n machinesstruct Node {int u, V, C, next;} E[maxm];int source, sink, tar, Maxday, Nv;int QUE[MAXN], LAYER[MAXN], pre[maxn];bool vis[maxn];void addedge (int u, int v, int c) {e[id].u = u;    E[ID].V = v; E[ID].C = C;    E[id].next = Head[u];    Head[u] = id++; e[id].u = v;    E[ID].V = u; e[id].c = 0;    E[id].next = Head[v]; HEAD[V] = id++;}     void Getmap () {int I, J, U, V, p, S, E;    id = tar = maxday = 0;    scanf ("%d%d", &m, &n);    Memset (Head,-1, sizeof (head)); Source = 0;    sink = 705;        for (i = 1; I <= m; ++i) {scanf ("%d%d%d", &p, &s, &e);        tar + = p;        if (E > maxday) maxday = e;        Addedge (source, I, p);    for (j = s; J <= E; ++j) Addedge (i, M + j, 1); } sink = m + maxday + 1;    NV = sink + 1; for (i = 1; I <= maxday; ++i) Addedge (M + i, sink, n);} BooL Countlayer () {memset (Layer, 0, sizeof (INT) * NV);    int id = 0, front = 0, u, V, I; Layer[source] = 1;    que[id++] = source;        while (front! = id) {u = que[front++];            for (i = head[u]; I! =-1; i = e[i].next) {v = e[i].v; if (e[i].c &&!)                Layer[v]) {Layer[v] = Layer[u] + 1;                if (v = = sink) return true;            else que[id++] = v; }}} return false;}    int dinic () {int i, u, V, mincut, Maxflow = 0, pos, id = 0;        while (Countlayer ()) {memset (Vis, 0, sizeof (BOOL) * NV);        memset (Pre,-1, sizeof (INT) * NV); que[id++] = source;        Vis[source] = 1;            while (id) {u = que[id-1];                if (U = = sink) {mincut = inf; for (i = pre[sink]; i =-1; i = pre[e[i].u]) if (Mincut > e[i].c) {mincut = E [I].c;                    pos = e[i].u;       } Maxflow + = Mincut;         for (i = pre[sink]; i =-1; i = pre[e[i].u]) {e[i].c-= mincut;                E[I^1].C + = Mincut;            } while (Que[id-1]! = POS) Vis[que[--id]] = 0; } else {for (i = head[u]; I! =-1; i = e[i].next) if (e[i].c && layer[u] + 1 = = L                    Ayer[v = e[i].v] &&!vis[v]) {vis[v] = 1; que[id++] = v; pre[v] = i; break;            } if (i = =-1)--id; }}} return maxflow;} void solve (int CAs) {printf ("Case%d:%s\n\n", cas, tar = = Dinic ()?) "Yes": "No");}    int main () {//Freopen ("Stdin.txt", "R", stdin);    int T, CAS;    scanf ("%d", &t);        for (cas = 1; CAs <= t; ++cas) {Getmap ();    Solve (CAS); } return 0;}


62ms

#include <stdio.h> #include <string.h> #define MAXN 1200#define maxm 700000int Head[maxn], N, m, id; n machinesstruct Node {int u, V, C, next;} E[maxm];int source, sink, tar, maxday, nv;const int inf = 0x3f3f3f3f;int CUR[MAXN], PS[MAXN], dep[maxn];void addedge (int u , int v, int c) {e[id].u = u;    E[ID].V = v; E[ID].C = C;    E[id].next = Head[u];    Head[u] = id++; e[id].u = v;    E[ID].V = u; e[id].c = 0;    E[id].next = Head[v]; HEAD[V] = id++;}     void Getmap () {int I, J, U, V, p, S, E;    id = tar = maxday = 0;    scanf ("%d%d", &m, &n);    Memset (Head,-1, sizeof (head));    Source = 0;        for (i = 1; I <= m; ++i) {scanf ("%d%d%d", &p, &s, &e);        tar + = p;        if (E > maxday) maxday = e;        Addedge (source, I, p);    for (j = s; J <= E; ++j) Addedge (i, M + j, 1); } sink = m + maxday + 1;    NV = sink + 1; for (i = 1; I <= maxday; ++i) Addedge (M + i, sink, n);} Parameters: Number of vertices. Source point, Meeting Point int dinic (inT n, int s, int t) {int TR, res = 0;    int I, j, K, F, R, top;        while (true) {memset (DEP,-1, n * sizeof (int));            for (f = dep[ps[0] = s] = 0, r = 1; F! = R;)                    for (i = ps[f++], j = head[i]; J! =-1; j = e[j].next) {if (e[j].c &&-1 = dep[k=e[j].v]) { DEP[K] = Dep[i] + 1;                    ps[r++] = k;                    if (k = = T) {f = R; break;        }}} if ( -1 = = dep[t]) break;        memcpy (cur, head, n * sizeof (int)); for (i = s, top = 0;;) {if (i = = t) {for (k = 0, tr = inf; k < top; ++k) if (e[ps[k]].c < TR) T                R = e[ps[f=k]].c;                for (k = 0; k < top; ++k) e[ps[k]].c-= TR, e[ps[k]^1].c + = TR; Res + = TR;            i = E[ps[top = f]].u; } for (j = cur[i]; Cur[i]! =-1; j = cur[i] = e[cur[i]].next) if (e[j].c && dep[i] + 1= = dep[e[j].v]) break;                if (cur[i]! =-1) {ps[top++] = Cur[i];            i = E[CUR[I]].V;                } else {if (0 = = top) break; Dep[i] =-1;            i = e[ps[--top]].u; }}} return res;} void solve (int CAs) {printf ("Case%d:%s\n\n", cas, tar = = Dinic (nv, source, sink)?

"Yes": "No");} int main () {//Freopen ("Stdin.txt", "R", stdin); int T, CAS; scanf ("%d", &t); for (cas = 1; CAs <= t; ++cas) {Getmap (); Solve (CAS); } return 0;}



HDU3572 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.