hdu3572 最大流
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Now she wonders whether he has a feasible schedule to finish all the tasks in time. She turns to you for help.
Input
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
Print a blank line after each test case.
Sample Input
Sample Output
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
const int MAXM = ;
struct node{
int to;
int val;
int next;
}edge[MAXM*];
int x[MAXN],y[MAXN],z[MAXN];
int pre[MAXN],vis[MAXN],ind,k,n,m,S,T;
void add(int x,int y,int z){
edge[ind].to = y;
edge[ind].val = z;
edge[ind].next = pre[x];
pre[x] = ind ++;
}
bool bfs(){
queue<int>q;
memset(vis,-,sizeof(vis));
vis[S] = ;
q.push(S);
while(!q.empty()){
int tp = q.front();
q.pop();
for(int i = pre[tp]; i != -; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == - && edge[i].val){
vis[t] = vis[tp] + ;
q.push(t);
}
}
}
return vis[T] != -;
}
int dfs(int rt,int low){
int used = ;
if(rt == T){
return low;
}
for(int i = pre[rt]; i != - && used < low; i = edge[i].next){
int t = edge[i].to;
if(vis[t] == vis[rt] + && edge[i].val){
int b = dfs(t,min(low-used,edge[i].val));
edge[i].val -= b;
edge[i^].val += b;
used += b;
}
}
if(used == ){
vis[rt] = -;
}
return used;
}
int main(){
int t,ff = ;
scanf("%d",&t);
while(t--){
scanf("%d%d",&m,&k);
ind = ;
memset(pre,-,sizeof(pre));
n = ;
ll all = ;
for(int i = ; i <= m; i++){
int fx,fy,fz;
scanf("%d%d%d",&fx,&fy,&fz);
x[i] = fy;
y[i] = fx;
z[i] = fz;
n = max(n,z[i]);
all += y[i];
}
for(int i = ; i <= m; i++){
for(int j = x[i]; j <= z[i]; j++){
add(i,j+m,),add(j+m,i,);
}
}
S = ,T = m + n + ;
for(int i = ; i <= m; i++){
add(S,i,y[i]),add(i,S,);
}
for(int i = ; i <= n; i++){
add(i+m,T,k),add(T,i+m,);
}
ll ans = ;
while(bfs()){
while(){
ll a = dfs(S,INF);
if(!a)break;
ans += a;
}
}
//cout<<S<<" "<<T<<endl;
printf("Case %d: ",++ff);
if(ans == all){
printf("Yes\n");
}
else {
printf("No\n");
}
printf("\n");
}
return ;
}
hdu3572 最大流的更多相关文章
- [hdu3572]最大流(dinic)
题意:有m台机器,n个任务,每个任务需要在第si~ei天之间,且需要pi天才能完成,每台机器每天只能做一个任务,不同机器每天不能做相同任务,判断所有任务是否可以做完. 思路: 把影响答案的对象提取出来 ...
- 【最大流】【HDU3572】Task Schedule
题意: 有N个事件,M台机器.事件有开始时间,持续时间,要在结束时间之前完成,问是否能完成所有事件? 非自己思考出来的 建图:把每个任务和每一天都看做一个点,添加源点和汇点.源点与每个任务之间连一条边 ...
- hdu3572 任务分配/最大流量推论全流
意甲冠军:将n分配的任务m机.到的每个任务需要的天数(如果没有持续的日常),并能做到在哪些天任务.询问是否有计划. 典型的任务(X)----日(Y)一半的最大流量,(因为这个任务是天之间的关系)处理器 ...
- hdu-3572 Task Schedule---最大流判断满流+dinic算法
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3572 题目大意: 给N个任务,M台机器.每个任务有最早才能开始做的时间S,deadline E,和持 ...
- hdu3572 任务分配/最大流判断满流
题意:将n个任务分配为m个机器,给每个任务需要的天数(无需每天连续),和可以在哪些天去做该任务,求是否存在方案. 典型的任务(X)----天(Y)二分最大流,(因为这里任务是与天的关系)处理器控制流量 ...
- HDU3572:Task Schedule【最大流】
上了一天课 心塞塞的 果然像刘老师那么说 如果你有挂科+4级没过 那基本上是WF队 题目大意:有时间补吧 思路:给每个任务向每个时间点连边容量为1 每个时间点向汇点连边 容量为机器的个数 源点向每个任 ...
- HDU3572 Task Schedule(最大流+构图思维)
题意: 有N个任务M个机器,给每个任务i完成所花费的时间Pi且每个任务要在第Si天后开始,在第Ei天前结束,保证任务在(S,E)之间一定能完成. 每个机器在一天里只能运行一个任务,一个任务可以在中途更 ...
- 最大流任务调度——hdu3572二分图建图
很简单的任务调度模板题 把一个工作完成一天的量当做是边 /* 任务调度问题最大流 因为两个任务之间是没有关系的,两天之间也是没有关系的 所以抽象成二分图 任务i在天数[si,ei]之间都连一条双向边, ...
- HDU3572 Task Schedule 【最大流】
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- ural Infernal Work
Infernal Work Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descr ...
- 第26章 创建型模式大PK
26.1 工厂方法模式 VS 建造者模式 26.1.1 按工厂方法建造超人 (1)产品:两类超人,成年超人和未成年超人. (2)工厂:这里选择简单工厂 [编程实验]工厂方法建造超人 //创建型模式大P ...
- ConcurrentHashMap是如何提高并发时的吞吐性能
为并发吞吐性能所做的优化 ConcurrentHashMap使用了一些技巧来获取高的并发性能,同时避免了锁.这些技巧包括: 为不同的Hash bucket(所谓hash bucket即不同范围的key ...
- mui禁止滚动条和禁止滚动
mui.plusReady(function () { plus.webview.currentWebview().setStyle({ scrollIndicator: 'none' }); }); ...
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- php正则表达式治疗结巴
用正则表达式去解决结巴这个问题可以通过下面进行解决: 解决思路是: 先找到重复的不部分 用str_replace($source,$replace,$str);来进行代理 下面分两种情况,最后将这两种 ...
- codevs 1033 蚯蚓的游戏问题
Description 在一块梯形田地上,一群蚯蚓在做收集食物游戏.蚯蚓们把梯形田地上的食物堆积整理如下: a(1,1) a(1,2)…a(1,m) a(2,1) a(2,2) a(2,3)…a ...
- LeetCode 01 Two Sum swift
class TwoSum { func sumTow(nums: [Int], target: Int)->[Int]{ ,]; ;x<nums.count;x++){ ;y<num ...
- jquery选择器空格与大于号、加号与波浪号的区别
空格:$('parent childchild')表示获取parent下的所有的childchild节点,所有的子孙. 大于号:$('parent > child')表示获取parent下的所有 ...
- 利用Weblogic的iisproxy、iisforward插件实现IIS转发
默认情况下,IIS只能提供http重定向功能,而无法满足转发需求. 举例:http://localhost/app1 利用http重定向到 http://www.abc.com/app1 访问 htt ...