URAL - 1949 The Best Picture in the Galaxy
来源:互联网 发布:java中list用法 编辑:程序博客网 时间:2024/06/10 07:26
传送门:http://acm.timus.ru/problem.aspx?space=1&num=1949
题意 : k 个学生去看n个电影,每个电影有自己的开始时间,结束时间和女演员数目,并且,要保证一个学生同时不能看两场电影,其次,学生看的第i+1个电影的女演员数目要不小于他看的第i的电影的女演员数。
求看最多的电影数目时,看了那几部,没看哪几部,1 表示看过0表示没看过
思路:二分图,但是要动态的去建图, 边建图,边检查,
当向图中加入一个新节点时候,我们要考虑以下几种情况:
1.这部电影是否能被当前已经看完电影的同学接着看(二分图匹配,看一下电影和之前电影之间能否构成连通分量)如果可以继续加点
2.这部电影被孤立,那么我们就要看下可否有没在看电影的学生,如果有,就让他看这部电影,然后继续加点
3.如果上述两种情况都不成立,那么这部电影舍去,不看
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <vector>using namespace std;#define MAXN 105#define inf 0x3f3f3f3fint lef[MAXN];bool del[MAXN];bool con[MAXN];vector<int> G[MAXN];bool match(int x){ for( int i = 0; i < G[x].size(); i++){ int v = G[x][i]; if(del[v]) continue; if(!con[v]){ con[v] = true; if(lef[v] == -1 || match(lef[v])){ lef[v] = x; return true; } } } return false;}int n, k, a[MAXN], b[MAXN], c[MAXN];int solve(){ memset(lef, -1, sizeof(lef)); int ans = 0; for(int i = 1; i <= n; i++){ if(del[i]) continue; memset(con, 0, sizeof(con)); if(match(i)) ans++; } return ans;}bool ok(int x, int y){ return(b[x] <= a[y] && c[x] <= c[y]);}int main(){ while(scanf("%d %d",&n, &k) != EOF){ memset(del, false, sizeof(del)); int delnum = 0; for( int i = 1; i <= n; i++){ G[i].clear(); scanf("%d %d %d",&a[i], &b[i], &c[i]); } for( int i = 1; i <= n; i++ ){ for( int j = 1; j < i; j++ ){ if(ok(i, j)) G[i].push_back(j); if(ok(j, i)) G[j].push_back(i); } int yes = 1; int tep = solve(); tep = i - delnum - tep; if(tep > k){ del[i] = true; delnum ++; yes = 0; } printf("%d",yes); } puts(""); } return 0;}
0 0
- URAL - 1949 The Best Picture in the Galaxy
- URAL 1949 The Best Picture in the Galaxy 二分匹配 求字典序最小解
- ural 1084. Goat in the Garden
- ural 1348. Goat in the Garden 2
- ural 1084 Goat in the Garden
- Goat in the Garden (ural 1348)
- Ural 1090. In the Army Now
- Ural 1090. In the Army Now
- ural 1090. In the Army Now
- ural 1804 The Machinegunners in a Playoff
- URAL 1090. In the Army Now
- URAL - 1145 Rope in the Labyrinth
- ural 1084. Goat in the Garden math
- URAL-1101. Robot in the Field
- 省赛 The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- The Best Seat in ACM Contest
- 08/13 D -> codeforces Round #Pi div 2 E. President and Roads 最短路变形
- 软件列表
- hdu5386Cover 暴力枚举
- AC算法初探
- Github 初次使用 commit命令提交失败
- URAL - 1949 The Best Picture in the Galaxy
- Servlet-ServletContextListener
- onReceivedTitle() 没被调用的解决
- Android 设置状态栏 显示 或 隐藏 SystemUI flag
- 连接池简介
- Eclipse创建Maven Web工程并实现Tomcat热部署
- 美国旅游签证办理流程
- 推荐程序开发书单
- UVALive - 5843 Furniture Factory