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)都是通 ...
随机推荐
- poj2141---字符串转换
#include <stdio.h> #include <stdlib.h> int main() { ]; char tmp; scanf("%s",ke ...
- Windows Server 2012 R2超级虚拟化之六 Hyper-v Replica 2.0和Live migrations
Windows Server 2012 R2超级虚拟化之六 Hyper-v Replica 2.0和Live migrations 分钟复制选项也是非常有用的.Hyper-V Replica 2.0在 ...
- 怎样通过css的media属性,适配不同分辨率的终端设备?
怎样通过css的media属性,适配不同分辨率的终端设备,示比例如以下: <!DOCTYPE html> <html> <head> <title>首页 ...
- Android SQLite 事务处理
应用程序初始化时需要批量的向sqlite中插入大量数据,单独的使用for+Insert方法导致应用响应缓慢,因为 sqlite插入数据的时候默认一条语句就是一个事务,有多少条数据就有多少次磁盘操作.我 ...
- 揭密: M2和高房价到底谁推高了谁?
近期,著名经济学家吴敬链向新华网等媒体表示:房价高的根本原本就是货币超发.近期十年来我国M2增长率(广义货币增长率)太快."钱太多了,有些人要保值就要投资买房,又因货币非常多购买力非常强.就 ...
- linux 使用sudo开放普通用户权限
整理一下以前写的东东,刚才又忘了- ---------------------------------------------------------------------------------- ...
- new、delete与malloc、free的详解
内容清单: 1. C语言中的函数malloc和free 2. C++中的运算符new和delete 3. new/delete与malloc/free之间的联系和区别 4. C/C++程序的内 ...
- SQL学习之汇总数据之聚集函数
一. 1.我们经常需要汇总数据而不用把他们实际检索出来,为此SQL提供了专门的函数,以便于分析数据和报表生成,这些函数的功能有: (1)确定表中行数(或者满足单个条件或多个条件或包含某个特定值的行数) ...
- 阿里P8分享:关于做事方式与做事态度
转载:http://www.neitui.me/y/1019 阿里P8分享:关于做事方式与做事态度贴图1: 贴图2: 贴图3:
- inline函数和一般的函数有什么不同
1.比如: int g(int x) { return x + x; } int f() { return g(); } 这样f会调用g,然后g返回x + x给f,然后f继续把那个值返回给调用者. 如 ...