POJ_1698_Alice's Chance
#include <iostream>
#include <queue>
#include <climits>
#include <cstring>
using namespace std;
const int MAX_SIZE = 400;
int capacity[MAX_SIZE][MAX_SIZE];
int parent[MAX_SIZE];
bool visit[MAX_SIZE]; bool Edmonds_Karp( int start, int end ){
queue<int> Q;
memset( visit, false, sizeof( visit ) );
visit[start] = true;
Q.push( start );
while( !Q.empty() ){
int temp = Q.front();
Q.pop();
for( int i = start; i <= end; ++i ){
if( capacity[temp][i] && !visit[i] ){
visit[i] = true;
parent[i] = temp;
Q.push( i );
if( i == end ) return true;
}
}
}
return false;
} int Ford_Fulkerson( int start, int end ){
int max_flow = 0;
while( true ){
if( !Edmonds_Karp( start, end ) ) break;
int flow = INT_MAX;
int path = end;
while( path != start ){
flow = min( flow, capacity[parent[path]][path] );
path = parent[path];
}
path = end;
while( path != start ){
capacity[path][parent[path]] += flow;
capacity[parent[path]][path] -= flow;
path = parent[path];
}
max_flow += flow;
}
return max_flow;
} int main(){
int t;
cin>>t;
while( t-- ){
int start = 0;
int end = MAX_SIZE - 1;
memset( capacity, 0, sizeof( capacity ) );
int film_num;
int sum_day = 0;
cin>>film_num;
for( int i = 1; i <= film_num; ++i ){
int flag[8];
int day, week;
for( int j = 1; j <= 7; ++j ) cin>>flag[j];
cin>>day>>week;
capacity[start][i] = day;
sum_day += day;
for( int p = 0; p < week; ++p ){
for( int q = 1; q <= 7; ++q ){
int index = film_num + 7 * p + q;
capacity[i][index] = flag[q];
if( flag[q] ) capacity[index][end] = 1;
}
}
}
/*
for( int i = 0; i <= film_num; ++i ){
for( int j = 0; j <= 40; ++j ){
cout<<capacity[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;*/
int max_flow = Ford_Fulkerson( start, end );
if( max_flow == sum_day ) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
POJ_1698_Alice's Chance的更多相关文章
- Chance – 功能强大的 JavaScript 随机数生成类库
Chance 是一个基于 JavaScript 的随机数工具类.可以生成随机数字,名称,地址,域名,邮箱,时间等等,几乎网站中使用的任何形式的内容都能够生成.这个随机数工具可以帮助减少单调的测试数据编 ...
- poj 1698 Alice‘s Chance
poj 1698 Alice's Chance 题目地址: http://poj.org/problem?id=1698 题意: 演员Alice ,面对n场电影,每场电影拍摄持续w周,每周特定几天拍 ...
- 【性能诊断】九、并发场景的性能分析(windbg案例,Fist Chance Exception/Crash dump)
经常会碰到这样的场景,自测及单单点的测试时没有任何问题,但在并发环境或生产环境下有时出现没规律的异常.报错等情况.在代码中增加日志是其中一种解决方式:抓取指定异常时的dump,通过wind ...
- (C# Debug)A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
Debug 模式下运行程序的时候,Output 窗口出来个错误“A first chance exception of type 'System.ArgumentException' occurred ...
- Alice's Chance POJ - 1698(按时间点建边)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7791 Accepted: 3174 De ...
- 2018.07.06 POJ1698 Alice's Chance(最大流)
Alice's Chance Time Limit: 1000MS Memory Limit: 10000K Description Alice, a charming girl, have been ...
- You can fail at what you don't want, so you might as well take a chance on doing what you love.
You can fail at what you don't want, so you might as well take a chance on doing what you love. 做不想做 ...
- Opportunity的chance of success的赋值逻辑
该字段的值和另外两个字段Sales Stage和Status都相关. 从下列function module CRM_OPPORT_H_PROB_SET_EC可看出,当status不为代码中的这些硬编码 ...
- 理解First Chance和Second Chance避免单步调试
原文链接地址:http://blog.csdn.net/Donjuan/article/details/3859160 在现在C++.Java..Net代码大行其道的时候,很多代码错误(Bug)都是通 ...
随机推荐
- [LeetCode][Python]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- css中的media
说起CSS3的新特性,就不得不提到 Media Queries .最近 Max Design 更新的一个泛读列表里,赫然就有关于 Media Queries 的文章.同时位列其中的也有前天我刚刚翻译的 ...
- 集合的实现 -- 数据结构与算法的javascript描述 第九章
集合 集合(set)是一种包含不同元素的数据结构. 集合中的元素称为成员. 集合的两个最重要特性是:首先,集合中的成员是无序的:其次,集合中不允许相同成员存在. code function Set() ...
- ASP.NET LINQ SQL执行超时的问题
最近在写一个航材取价的程序.由于执行的语句复杂,数据量比较大,容易造成超时. 看提示应该是执行SQL的时候超时,我在程序中用的linq. 实际把SQL语句单独执行的时候观察也要40秒左右. 查资料得知 ...
- debug jdk
1.解压jdk安装路径中的src.zip如:c:\src. 注意一般只选择编译java javax org 三个文件夹就足够了,剩余的文件夹删除掉 2.列出要编译的源文件:dir /B /S /X c ...
- [Swust OJ 1139]--Coin-row problem
题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...
- C# Excel或表格插件
NOPI好像比较好用对WINFORM支持更好! http://www.cnblogs.com/dreamof/archive/2010/06/02/1750151.html NOPI教程 http:/ ...
- VS插件
VS插件 背景 前些天去考科目二,感觉经历了一场不是高考却胜似高考的考试(10年前的5分之差, 还是难以释怀)! 一行八人,就我学的时间最少(4天,8人一辆车),教练都觉得我肯定还得再来一次! ...
- 在两个Android设备间通过UDP传输目录内文件
这两天下了一个使用UDP传输目录内文件的程序,发出来给大家一起看看,共同进步.有问题请指教. 由于udp丢包比较厉害,因此使用了自定义的内部协议,进行双方的确认. 程序跑起来后,看网络状况,有时候会一 ...
- mysql 批量删除分区
alter table titles drop partition p01; use zabbix; mysql> source drop_par.sql [oracle@oadb mysql] ...