Problem Solving Report
Test instructions
Factory has m machine, need to do n tasks. For a task I. You need to spend a machine pi days, and the time to start doing this task is >=si, and the time to complete this task is <=ei.
For a task, it can only be completed by a machine. A machine can only do one task at a time.
However, a task can be divided into several periods of time to complete. Ask if you can finish all the tasks.
Ideas:
The network flow is modeled, and the modeling method is:
Think of each day and every task as a point. From the source point to each task. Build a PI-capacity edge (indicating how many days the task needs to be completed).
Every task to every day , if you can do the task on this day, build a capacity of 1 side. At last. Build a side capacity m (which indicates the maximum number of M tasks per machine) to the meeting point each day.
#include <map> #include <queue> #include <vector> #include <cstdio> #include <cstring># Include <iostream> #define INF 99999999using namespace std;int n,m,l[2010],head[2010],cnt,m;struct node{int v,w,n ext;} edge[555000];void Add (int u,int v,int W) {edge[m].v=v; Edge[m].w=w; Edge[m].next=head[u]; head[u]=m++; Edge[m].v=u; edge[m].w=0; EDGE[M].NEXT=HEAD[V]; head[v]=m++;} int BFs () {memset (l,-1,sizeof (l)); l[0]=0; int i,u,v; Queue<int >Q; Q.push (0); while (! Q.empty ()) {U=q.front (); Q.pop (); for (i=head[u]; i!=-1; i=edge[i].next) {v=edge[i].v; if (l[v]==-1&&edge[i].w>0) {l[v]=l[u]+1; Q.push (v); }}} if (l[cnt]>0) return 1; return 0;} int dfs (int u,int f) {int a,i; if (u==cnt) return F; for (i=head[u]; i!=-1; i=edge[i].next) {int v=edge[i].v; if (l[v]==l[u]+1&&edge[i].w>0&& (A=dfs (V,min (F,EDGE[I].W)))) {edge[i].w-=a; Edge[i^1].w+=a; return A; }} l[u]=-1;//does not add optimization will t return 0;} int main () {int t,i,j,s,p,e,k=1; scanf ("%d", &t); while (t--) {m=0; memset (head,-1,sizeof (head)); scanf ("%d%d", &n,&m); int sum=0,maxx=0; for (I=1; i<=n; i++) {scanf ("%d%d%d", &p,&s,&e); Add (0,i,p); Sum+=p; if (maxx<e) maxx=e; for (J=s; j<=e; j + +) Add (i,j+n,1); } cnt=n+maxx+1; for (I=1; i<=maxx; i++) {Add (n+i,cnt,m); } int ans=0,a; while (BFS ()) while (A=dfs (0,inf)) ans+=a; printf ("Case%d:", k++); if (ans==sum) printf ("yes\n"); else printf ("no\n"); printf ("\ n"); } return 0;}
Task ScheduleTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3311 Accepted Submission (s): 1154
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
Source
field=problem&key=2010%20acm-icpc%20multi-university%20training%20contest%a3%a813%a3%a9%a1%aa%a1%aahost% 20by%20uestc&source=1&searchmode=source "style=" Color:rgb (26,92,200); Text-decoration:none ">2010 acm-icpc multi-university Training Contest (--host by UESTC)
Hdu3572_task Schedule (maximum stream of network streams)