Task Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4003    Accepted Submission(s): 1347
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

题意:有n个机器,m项任务,每一个任务须要Pi天时间,开工日期到收工日期为Si到Ei。一次仅仅能在一台机器上加工,能够挪到别的机器上,问是否能按期完毕全部任务。

题解:这题关键在构图,设置一个源点到每项任务有一条边,容量为该项任务所须要的天数,每项任务到合法加工日期内的每一个天数加一条边,容量为1,即每天工作量为1。然后每一个天数到汇点加入一条边,容量为机器数量n。表示一天最大加工量。

218ms

#include <stdio.h>
#include <string.h> #define maxn 1200
#define maxm 700000
#define inf 0x3f3f3f3f int head[maxn], n, m, id; // n machines
struct 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 == Layer[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 700000 int head[maxn], n, m, id; // n machines
struct 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);
} // 參数:顶点个数。源点,汇点
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) tr = 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 【最大流】的更多相关文章

  1. HDU3572 Task Schedule(最大流+构图思维)

    题意: 有N个任务M个机器,给每个任务i完成所花费的时间Pi且每个任务要在第Si天后开始,在第Ei天前结束,保证任务在(S,E)之间一定能完成. 每个机器在一天里只能运行一个任务,一个任务可以在中途更 ...

  2. HDU 3572 Task Schedule (最大流)

    C - Task Schedule Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  3. HDU3572:Task Schedule【最大流】

    上了一天课 心塞塞的 果然像刘老师那么说 如果你有挂科+4级没过 那基本上是WF队 题目大意:有时间补吧 思路:给每个任务向每个时间点连边容量为1 每个时间点向汇点连边 容量为机器的个数 源点向每个任 ...

  4. hdu-3572 Task Schedule---最大流判断满流+dinic算法

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3572 题目大意: 给N个任务,M台机器.每个任务有最早才能开始做的时间S,deadline E,和持 ...

  5. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. hdu 3572 Task Schedule(最大流&amp;&amp;建图经典&amp;&amp;dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. hdu 3572 Task Schedule

    Task Schedule 题意:有N个任务,M台机器.每一个任务给S,P,E分别表示该任务的(最早开始)开始时间,持续时间和(最晚)结束时间:问每一个任务是否能在预定的时间区间内完成: 注:每一个任 ...

  8. hdu 3572 Task Schedule (dinic算法)

    pid=3572">Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU3572Task Schedule(最大流 ISAP比較快)建图方法不错

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. 如何清除win7开机密码

    一.电脑已经登录到系统,但是忘记了密1对于这种情况是最简单的,其实只需要将密码取消就可以了右键单击桌面上我的电脑,选择管理即可进入计算机管理界面2依次展开系统工具--本地用户和组--用户,在右侧选择要 ...

  2. UVA 12532-Interval Product(BIT)

    题意: 给n个数字的序列,C v p 把v位上的数字置成p , S l r代表求区间[l,r]各数字相乘得数的符号,对于每个S输出所得符号(’+‘,’-‘,’0‘) 分析: 开两个数组表示区间负数的个 ...

  3. Apache OFBiz 学习笔记 之 服务引擎 一

    概述     服务定义为一段独立的逻辑顺序,当多个服务组合一起时可完成不同类型的业务需求     服务有很多类型,WorkFlow.Rules.Java.SOAP.BeanShell等.java类型的 ...

  4. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 page_should_not_contain_list(self, locator, message='', loglevel='INFO')

    def page_should_not_contain_list(self, locator, message='', loglevel='INFO'): """Veri ...

  5. css3 javascript 实现菜单按钮特效

    一个菜单按钮特效案例,简单的实现了动态效果. 代码效果预览地址: http://code.w3ctech.com/detail/2504 <div class="bar" i ...

  6. Android版本判断

    尽管Android向下兼容不好,但是一个程序还是可以在多个平台上跑的.向下兼容不好,接口改变,新的平台上不能用旧的API,旧的平台更不可能用新的API,不等于一个平台需要一个APK.可以在高版本的SD ...

  7. GridView控件 Reapter控件 DataList控件 的区别和用法

    ASP.NET三大控件: 1.GridView控件:表格视图控件,可以用来绑定结果集或者视图,用起来比较方便和灵活,三个控件中使用最多的控件 用法--- this.gridview1.DataSour ...

  8. 第二百七十四、五、六天 how can I 坚持

    三天小长假这么快就过去了,好快啊.基本都是在济南过的. 元旦.坐车回济南.下午在万科新里程看了一下午房子,没有买啊,93的现在八千六七,有点贵啊,户型也不是自己喜欢的. 晚上一块吃了个饭,还行,晚上在 ...

  9. hibernate 打印sql和参数的配置

    1.配置spring-hiberbate.xml:<prop key="hibernate.show_sql">true</prop>--强制打印sql 不 ...

  10. struts2+Hibernate4+spring3+EasyUI环境搭建之五:引入jquery easyui

    1.下载jquery easyui组件     http://www.jeasyui.com/download/index.php 2.解压 放到工程中  如图 3.jsp引入组件:必须按照如下顺序 ...