HDU 1498 50 years, 50 colors(最小点覆盖,坑题)
来源:互联网 发布:jquery.js文件下载 编辑:程序博客网 时间:2024/05/19 19:44
50 years, 50 colors
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
有这样一个矩阵,矩阵里面是气球,气球有颜色编号1-50,询问在k次之内能不能把同种颜色存在的气球消掉(每次询问有K次机会),超过K此的气球编号,储存起来,并按编号按升序输出。
题意不是很好理解,但是看明白之后,就很清晰了
求最小点覆盖——即 用最少的点覆盖图中最多的边。
依次枚举就可以
矩阵的一维下标 当做 X集合,二维下标当做Y集合,询问所有点的最大匹配,比K大自然不满足
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <math.h>#define init(a) memset(a,0,sizeof(a))#define PI acos(-1,0)using namespace std;const int maxn = 110;const int maxm = 100001;#define lson left, m, id<<1#define rson m+1, right, id<<1|1#define min(a,b) (a>b)?b:a#define max(a,b) (a>b)?a:bconst int N = 50010;int ma[maxn][maxn];int line[maxn],res[maxn];bool vis[maxn],bj[maxn];int k,n,m,t;int cmp(const void *a,const void *b){ return *(int *)a - *(int *)b;}int DFS(int st,int u){ for(int v = 1;v<=n;v++) { if(ma[u][v]== st && !vis[v]) { vis[v] = 1; if(line[v]==-1 || DFS(st,line[v])) { line[v] = u; return 1; } } } return 0;}int K_M(int st){ memset(line,-1,sizeof(line)); int ans = 0; for(int i = 1;i<=n;i++) { init(vis); ans += DFS(st,i); } return ans;}int main(){ int t; while(~scanf("%d%d",&n,&k)) { if(n==0 && k== 0) break; init(ma); init(res); init(bj); for(int i = 1;i<=n;i++) { for(int j = 1;j<=n;j++) { scanf("%d",&t); ma[i][j] = t; if(!bj[t]) bj[t] = 1; } } int cnt,num = 0; for(int i = 1;i<=55;i++) { if(bj[i]) { cnt = K_M(i); (cnt>k)?(res[num++] = i):(1); } } if(num==0) puts("-1"); else { //sort(res,res+num); qsort(res,num,sizeof(res[0]),cmp); for(int j = 0;j<num-1;j++) printf("%d ",res[j]); printf("%d\n",res[num-1]); } } return 0;}
0 0
- 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 【最小点覆盖】
- 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 二分图最小点覆盖
- 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 50 years, 50 colors(枚举点,最小点覆盖)
- hdu1498 50 years, 50 colors (最小点覆盖)
- hdu1498 50 years, 50 colors --- 最小点覆盖
- hdu1498—50 years, 50 colors(最小点覆盖)
- hdu 3879 hdu 3917 构造最大权闭合图 俩经典题
- poj 1236
- [C++] vector数组越届及关于引用的
- 分析最常见最有效的公共传播方方式
- Maven
- HDU 1498 50 years, 50 colors(最小点覆盖,坑题)
- 线性检索:顺序检索
- 智慧农业物联网方案,zigbee无线CDMA,GPRS数传大棚灌溉温湿度
- python函数返回值
- Elixir 入门
- 字符串相似度--动态规划
- leetcode Populating Next Right Pointers in Each Node &&Populating Next Right Pointers in Each Node||
- POJ 1469 COURSES(二分图最大匹配)
- Uncle Tom's Inherited Land* 6.3.7