Alice's Chance
id=1698" style="background-color:rgb(51,255,51)">主题链接
- 意甲冠军:
爱丽丝要拍电影。有n部电影,规定爱丽丝第i部电影在每一个礼拜仅仅有固定的几天能够拍电影,且仅仅能在前wi个周拍,而且这部电影要拍di天才干结束。问爱丽丝能不能拍全然部的电影
第一行代表有多少组数据,对于每组数据第一行代表有n部电影,接下来2到n+1行,每行代表一个电影,每行9个数,前面7个数,1代表拍。0代表不拍,第8个数代表要拍几天,第9个数代表有几个礼拜时间拍 - 分析:
对于每一个电影。di - x[0] - x[1] - ... - x[t] = 0,di表示这个电影须要的天数,x[]表示电影相应的这些天是否选择(取值为零或一)
对于每一天。y[0] - y[1] - ... - y[t] <= 1,1表示这一天最多拍一个电影。y[]表示相应的电影是否在这一天拍(取值为零或一)
struct Edge
{
int from, to, cap, flow;
bool operator< (const Edge& rhs) const
{
return from < rhs.from || (from == rhs.from && to < rhs.to);
}
}; const int MAXV = 500;
struct ISAP
{
int n, m, s, t;
vector<Edge> edges;
vector<int> G[MAXV]; // 邻接表。G[i][j]表示结点i的第j条边在e数组中的序号
bool vis[MAXV]; // BFS使用
int d[MAXV]; // 从起点到i的距离
int cur[MAXV]; // 当前弧指针
int p[MAXV]; // 可增广路上的上一条弧
int num[MAXV]; // 距离标号计数 void AddEdge(int from, int to, int cap)
{
edges.push_back((Edge) { from, to, cap, 0 });
edges.push_back((Edge) { to, from, 0, 0 });
m = edges.size();
G[from].push_back(m-2);
G[to].push_back(m-1);
} bool BFS()
{
memset(vis, 0, sizeof(vis));
queue<int> Q;
Q.push(t);
vis[t] = 1;
d[t] = 0;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
REP(i, G[x].size())
{
Edge& e = edges[G[x][i]^1];
if(!vis[e.from] && e.cap > e.flow)
{
vis[e.from] = 1;
d[e.from] = d[x] + 1;
Q.push(e.from);
}
}
}
return vis[s];
} void ClearAll(int n)
{
this->n = n;
REP(i, n)
G[i].clear();
edges.clear();
} void ClearFlow()
{
REP(i, edges.size())
edges[i].flow = 0;
} int Augment()
{
int x = t, a = INF;
while(x != s)
{
Edge& e = edges[p[x]];
a = min(a, e.cap-e.flow);
x = edges[p[x]].from;
}
x = t;
while(x != s)
{
edges[p[x]].flow += a;
edges[p[x]^1].flow -= a;
x = edges[p[x]].from;
}
return a;
} int Maxflow(int s, int t, int need)
{
this->s = s;
this->t = t;
int flow = 0;
BFS();
memset(num, 0, sizeof(num));
REP(i, n) num[d[i]]++;
int x = s;
memset(cur, 0, sizeof(cur));
while(d[s] < n)
{
if(x == t)
{
flow += Augment();
if(flow >= need) return flow;
x = s;
}
int ok = 0;
FF(i, cur[x], G[x].size())
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow && d[x] == d[e.to] + 1) // Advance
{
ok = 1;
p[e.to] = G[x][i];
cur[x] = i; // 注意
x = e.to;
break;
}
}
if(!ok) // Retreat
{
int m = n-1; // 初值注意
REP(i, G[x].size())
{
Edge& e = edges[G[x][i]];
if(e.cap > e.flow)
m = min(m, d[e.to]);
}
if(--num[d[x]] == 0)
break;
num[d[x] = m + 1]++;
cur[x] = 0; // 注意
if(x != s)
x = edges[p[x]].from;
}
}
return flow;
} vector<int> Mincut() // call this after maxflow
{
BFS();
vector<int> ans;
REP(i, edges.size())
{
Edge& e = edges[i];
if(!vis[e.from] && vis[e.to] && e.cap > 0)
ans.push_back(i);
}
return ans;
} void Reduce()
{
REP(i, edges.size())
edges[i].cap -= edges[i].flow;
} void print()
{
printf("Graph:\n");
REP(i, edges.size())
printf("%d->%d, %d, %d\n", edges[i].from, edges[i].to , edges[i].cap, edges[i].flow);
}
} mf; int day[18]; int main()
{
int T, n, d, w;
RI(T);
FE(kase, 1, T)
{
int sum = 0;
RI(n);
mf.ClearAll(n + 7 * 50 + 2);
int S = 0, T = n + 7 * 50 + 1, Max = -1;
FE(i, 1, n)
{
FE(j, 1, 7)
RI(day[j]);
RII(d, w);
sum += d;
Max = max(Max, w);
mf.AddEdge(S, i, d);
FE(j, 1, 7)
if (day[j])
{
REP(k, w)
mf.AddEdge(i, n + k * 7 + j, 1);
}
}
FE(i, 1, 7) REP(j, Max)
mf.AddEdge(n + j * 7 + i, T, 1);
printf("%s\n", mf.Maxflow(S, T, INF) == sum ? "Yes" : "No");
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Alice's Chance的更多相关文章
- POJ 1698 Alice's Chance(最大流+拆点)
POJ 1698 Alice's Chance 题目链接 题意:拍n部电影.每部电影要在前w星期完毕,而且一周仅仅有一些天是能够拍的,每部电影有个须要的总时间,问能否拍完电影 思路:源点向每部电影连边 ...
- poj 1698 Alice's Chance 拆点最大流
将星期拆点,符合条件的连边,最后统计汇点流量是否满即可了,注意结点编号. #include<cstdio> #include<cstring> #include<cmat ...
- HDU 4791 & ZOJ 3726 Alice's Print Service (数学 打表)
题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showP ...
- HDU 4791 Alice's Print Service 水二分
点击打开链接 Alice's Print Service Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 4122 Alice's mooncake shop (线段树)
题目大意: 一个月饼店每一个小时做出月饼的花费不一样. 储存起来要钱.最多存多久.问你把全部订单做完的最少花费. 思路分析: ans = segma( num[]*(cost[] + (i-j)*s) ...
- 2-sat(石头、剪刀、布)hdu4115
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu 4115 Eliminate the Conflict ( 2-sat )
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu4115 Eliminate the Conflict
Eliminate the Conflict Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Spark GraphX实例(2)
5. 图的转换操作 图的转换操作主要有以下的方法: (1) Graph.mapVertices():对图的顶点进行转换,返回一张新图: (2) Graph.mapEdges():对图的边进行转换,返回 ...
随机推荐
- Android游戏源代码合集(主要是AndEngine和Libgdx的)
近期在网络上看到有网友抱怨Android游戏源代码找不到,所以小弟收集了一些AndEngine和Libgdx的游戏源代码,以Eclipseproject的形式配置好环境,再陆续发出(某引擎避嫌,不在此 ...
- C++编程有趣的标题1 于1~9填写的运算结果的中间符号等于100
于1 2 3 4 5 6 7 8 9将九个数字"+"要么"-"符号使得结果100,编程的所有组合. 注意:数字顺序不能改变 <pre name=" ...
- HTML的标签使用
<p>段落标签</p>:段落标签 <hx>标题标签</hx>:标题标签,x代表1-6 <em>斜体</em>:显示的字体是斜的 ...
- 5月,专用程序猿的经典大作——APUE
五一小长假刚刚过去,收回我们游走的心.開始你们的读书旅程吧! 本期特别推荐 经典UNIX著作最新版. 20多年来,这本书帮助几代程序猿写出强大.高性能.可靠的代码. 第3版依据当今主流系统进行更新,更 ...
- ubuntu快捷键设置,查看系统
设置system setting于.点击键盘keyboard,有捷径keyboard shortcut.但也设置快捷键本身. 版权声明:本文博主原创文章,博客,未经同意不得转载.
- 2013成都邀请赛J称号||HDU4725 The Shortest Path in Nya Graph(spfa+slf最短的优化)
职务地址:HDU 4725 这题卡了好长时间了,建图倒是会建,可是不会最短路的算法优化,本以为都须要堆去优化的,打算学了堆之后再来优化.可是昨晚CF的一道题..(那题也是不优化过不了..)然后我就知道 ...
- Redis实现分布式锁与任务队列
Redis实现分布式锁 与 实现任务队列 这一次总结和分享用Redis实现分布式锁 与 实现任务队列 这两大强大的功能.先扯点个人观点,之前我看了一篇博文说博客园的文章大部分都是分享代码,博文里强调说 ...
- 鸟哥Linux私房菜知识汇总8至9章
一看最近<鸟哥Linux私房菜>. 这是一个基本的书,万丈高楼平地起,学. 这是我整理的一些知识点.尽管非常基础. 希望和大家共同交流. 第8章 Linux磁盘与文件系统管理 一.Linu ...
- W5500EVB TCP Client模式设置说明
W5500EVB是WIZnet为了方便用户更好了解.使用W5500这款网络芯片所开发的评估板,该板採用了 STM32F103RCT6+W5500 的设计.基于 ARM 的 Cortex-M3 平台.那 ...
- 8.19! 今天我有18生日,点击阅读或顶部 尾随幸运的一天!生日知识!↓——【Badboy】
话说得生疼.我已经想到了17那年,那是一年的时间!我在这里7.24我认为这是我的生日 结果到处宣传 ,首页疑问发现自己是错的生日 按照农历计勒把我羞辱. 不依照原农历7.24的 今天的国家今天的日历 ...