poj 1698 Alice's Chance(ek算法)
来源:互联网 发布:兄弟连java百度云盘 编辑:程序博客网 时间:2024/05/21 20:00
Alice's Chance
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 5280 Accepted: 2171
Description
Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films.
As for a film,
For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week.
Notice that on a single day Alice can work on at most ONE film.
As for a film,
- it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days;
- Alice should work for it at least for specified number of days;
- the film MUST be finished before a prearranged deadline.
For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week.
Notice that on a single day Alice can work on at most ONE film.
Input
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of "F1 F2 F3 F4 F5 F6 F7 D W". Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.
Output
For each test case print a single line, 'Yes' if Alice can attend all the films, otherwise 'No'.
Sample Input
220 1 0 1 0 1 0 9 30 1 1 1 0 0 0 6 420 1 0 1 0 1 0 9 40 1 1 1 0 0 0 6 2
Sample Output
YesNo
Hint
A proper schedule for the first test case:date Sun Mon Tue Wed Thu Fri Satweek1 film1 film2 film1 film1week2 film1 film2 film1 film1week3 film1 film2 film1 film1week4 film2 film2 film2
2、每一天都当做一个点,然后如果这一天能演某个电影,则把该点和这个电影连一条边,边权为1;同时,把这一点和汇点连一条边,边权也为1.
3、求超级源点到汇点的最大流,若最大流等于总天数则输出Yes!!
#include"stdio.h"#include"string.h"#include"queue"using namespace std;#define N 505const int inf=10000000;int g[N][N];int pre[N],mark[N];int min(int a,int b){return a<b?a:b;}int ek(int n){ int i,u,ans=0; while(1) { queue<int>q; q.push(0); memset(mark,0,sizeof(mark)); memset(pre,-1,sizeof(pre)); mark[0]=1; while(!q.empty()) { u=q.front(); q.pop(); for(i=0;i<=n;i++) { if(!mark[i]&&g[u][i]) { mark[i]=1; pre[i]=u; q.push(i); } } } if(pre[n]==-1) break; int d=inf; for(i=n;i!=0;i=pre[i]) { d=min(d,g[pre[i]][i]); } for(i=n;i!=0;i=pre[i]) { g[pre[i]][i]-=d; g[i][pre[i]]+=d; } ans+=d; } //printf("%d\n",ans); return ans;}int main(){ int i,j,k,n,t,u,sum,T; int a[22][8],d[22],w[22]; scanf("%d",&T); while(T--) { scanf("%d",&n); memset(g,0,sizeof(g)); sum=t=0; //汇点 for(i=1;i<=n;i++) { for(j=0;j<7;j++) { scanf("%d",&a[i][j]); } scanf("%d%d",&d[i],&w[i]); if(w[i]>t) t=w[i]; } t=t*7+n+1; //汇点的下标 for(i=1;i<=n;i++) { g[0][i]=d[i]; //超级源点到一般源点(电影所需天数)的边权 for(k=0;k<w[i];k++){for(j=0;j<7;j++){if(a[i][j]){ u=k*7+j+n+1;g[i][u]=g[u][t]=1;}}} sum+=d[i]; } if(sum==ek(t)) printf("Yes\n"); else printf("No\n"); } return 0;}
0 0
- poj 1698 Alice's Chance(ek算法)
- POJ 1698 Alice's Chance ( EK )
- POJ 1698 Alice's Chance
- POJ 1698 Alice's Chance
- poj 1698 Alice's Chance
- POJ 1698 Alice's Chance
- poj 1698 Alice's Chance
- POJ 1698 Alice's Chance
- POJ 1698 Alice's Chance
- poj-1698-Alice's Chance
- (最大流) POJ 1698 Alice's Chance
- POJ 1698Alice's Chance(最大流)
- poj 1698 Alice's Chance 网络流
- 【POJ】1698 Alice's Chance 最大流
- POJ 1698 Alice's Chance(最大流)
- POJ 1698 Alice's Chance 最大流
- POJ 1698 Alice's Chance(最大流)
- POJ 1698 —— Alice's Chance
- Ios - UIView 添加背景图片
- HDU_2032 杨辉三角
- 2014杭电多校联合第三场 1005
- // 2、有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)。
- Linux 之top命令
- poj 1698 Alice's Chance(ek算法)
- Android测试
- hdoj.2031 进制转换 20140729
- 3.定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打
- ubuntu下mysql远程连接
- hdoj.2032 杨辉三角 20140729
- 一入python深似海--小爬虫
- 设计计时器
- java蓝桥杯 B组(二)