Task Schedule
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6422 Accepted Submission(s): 2024
Problem Description
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
Author
allenlowesy
Source
2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC
题意:工厂有m台机器,需要做n个任务。对于一个任务i,你需要花费一个机器Pi天,而且,开始做这个任务的时间要>=Si,完成这个任务的时间<=Ei。对于一个任务,只能由一个机器来完成,一个机器同一时间只能做一个任务。但是,一个任务可以分成几段不连续的时间来完成。问,能否做完全部任务。
诈一看,感觉是一道贪心题……这种题用网络流做的话,难都不在于网络流算法,而是建图的过程,因为这是一个很抽象的过程……这里我们建图的过程就是:把每一天和每个任务看做点。由源点到每一任务,建容量为pi的边(表示任务需要多少天完成)。每个任务到每一天,若是可以在这天做任务,建一条容量为1的边,最后,把每天到汇点再建一条边容量m。