HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)
来源:互联网 发布:虫族建筑知乎 编辑:程序博客网 时间:2024/05/23 17:49
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2293 Accepted Submission(s): 1292
Problem Description
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nice, isn't it? To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there will be a game named "crashing color balloons".
There will be a n*n matrix board on the ground, and each grid will have a color balloon in it.And the color of the ballon will be in the range of [1, 50].After the referee shouts "go!",you can begin to crash the balloons.Every time you can only choose one kind of balloon to crash, we define that the two balloons with the same color belong to the same kind.What's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. Of course, a lot of students are waiting to play this game, so we just give every student k times to crash the balloons.
Here comes the problem: which kind of balloon is impossible to be all crashed by a student in k times.
There will be a n*n matrix board on the ground, and each grid will have a color balloon in it.And the color of the ballon will be in the range of [1, 50].After the referee shouts "go!",you can begin to crash the balloons.Every time you can only choose one kind of balloon to crash, we define that the two balloons with the same color belong to the same kind.What's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. Of course, a lot of students are waiting to play this game, so we just give every student k times to crash the balloons.
Here comes the problem: which kind of balloon is impossible to be all crashed by a student in k times.
Input
There will be multiple input cases.Each test case begins with two integers n, k. n is the number of rows and columns of the balloons (1 <= n <= 100), and k is the times that ginving to each student(0 < k <= n).Follow a matrix A of n*n, where Aij denote the color of the ballon in the i row, j column.Input ends with n = k = 0.
Output
For each test case, print in ascending order all the colors of which are impossible to be crashed by a student in k times. If there is no choice, print "-1".
Sample Input
1 112 11 11 22 11 22 25 41 2 3 4 52 3 4 5 13 4 5 1 24 5 1 2 35 1 2 3 43 350 50 5050 50 5050 50 500 0
Sample Output
-1121 2 3 4 5-1
话说这个术语叫最小顶点覆盖,用最少的顶点覆盖最多的行列数,覆盖数就是二分图最大匹配数,不过要把模板做一点调整
用vector写的,不喜欢用矩阵
#include<cstdio>#include<cstring>#include<vector>#include<algorithm>#define ll long long#define maxn 101#define inf 0x3f3f3f3f#define mes(a, b) memset(a, b, sizeof(a))using namespace std;int link[maxn], put[maxn];int map[maxn][maxn];bool vis[maxn], mark[maxn];int n;vector<int > edge[maxn];bool match(int u, int val){ for(int i = 0; i < edge[u].size(); i++){ int v = edge[u][i]; if(!vis[i] && v == val){//核心就在这里了,把模板的vis标记以及link的连接从edge[u][i]这个值,改为i这个列数 vis[i] = true; //再加一个v=val做判断,画幅图很好理解 if(link[i] == -1 || match(link[i], val)){ link[i] = u; return true; } } } return false;}int Getmatch(int c){//获取最大匹配 int ans = 0; mes(link, -1); for(int i = 1; i <= n; i++){ mes(vis, false); if(match(i, c)){//传入c作一个比较值 ans++; } } return ans;}int main(){ int t, k; while(~scanf("%d%d", &n, &k), k || n){ mes(mark, false); for(int i = 1; i <= n; i++){ edge[i].clear(); for(int j = 1; j <= n; j++){ scanf("%d", &t); mark[t] = true; edge[i].push_back(t); } } int cnt = 0; for(int i = 1; i <= 50; i++){//气球一共50种,遍历出现过的就可以了,mark标记出现 if(mark[i] && Getmatch(i) > k){ put[cnt++] = i; } } if(!cnt){ printf("-1\n"); continue; } for(int i = 0; i < cnt; i++){ printf("%d%c", put[i], i == cnt-1 ? '\n' : ' '); } } return 0;}
0 0
- HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)
- 【二分图匹配(最小顶点覆盖)】hdu 1498 50 years,50 colors
- HDU 1498 50 years, 50 colors (二分图最小顶点覆盖)
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- HDU 1498 50 years, 50 colors(最小顶点覆盖)
- HDOJ 1498 - 50 years, 50 colors 水二分图..二分图最小点覆盖
- 50 years, 50 colors 【最小顶点覆盖】
- HDOJ 1498 —— 50 years, 50 colors 二分图匹配(最小点覆盖 = 最大二分匹配)
- hdoj 1498 50 years, 50 colors (二分图--最小点覆盖)
- HDU-1498-50 years,50 colors【二分匹配】【最小顶点覆盖】
- hdoj 1498 50 years, 50 colors 【最小点覆盖】
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
- hdu 1498 50 years, 50 colors(枚举,最小顶点覆盖)
- HDU 1498 50 years, 50 colors 二分图最小点覆盖(基础题)
- hdu1498 50 years, 50 colors(最小顶点覆盖)
- hdu149850 years, 50 colors (多个最小顶点覆盖)
- HDOJ 题目1498 50 years, 50 colors(最小点覆盖)
- chrome gn,gyp使用
- array_map(myfunction,array1,array2,array3...) array_walk(array,myfunction,userdata...)
- JS实现鼠标点击展开或隐藏表格行的方法
- IBM 专业的统计分析平台SPSS Statistics 24.0新功能介绍
- 浅谈BigDecimal
- HDOJ-----1498--50 years, 50 colors二分图(最小顶点覆盖)
- Java ConcurrentModificationException异常原因和解决方法
- lintcode斐波那契数列
- 关于进度条(ProgressBar)那些事(笔记)
- zabbix3.0 ubunt14.04安装
- tjut 3095
- poj1797
- Android studio 导入github工程
- EF映射入门