HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
2015-12-13 14:36
453 查看
50 years, 50 colors
Problem DescriptionOn 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.
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 1 1 2 1 1 1 1 2 2 1 1 2 2 2 5 4 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1 2 3 5 1 2 3 4 3 3 50 50 50 50 50 50 50 50 50 0 0
Sample Output
-1 1 2 1 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:b const 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; }
相关文章推荐
- linux用户及权限管理-学习总结
- JSP实现计算器功能(网页版)
- JSP利用过滤器解决request中文乱码问题
- uva10167 (简单题)
- 自定义异常
- oracle临时表的使用(未完)
- EJB通过ANT提高EJB应用程序的开发效率、无状态发展本地接口bean、开发状态bean
- makefile模板
- 设置器(setter)和访问器(getter)的使用方法
- java中System类简介(转)
- Linux用户及权限管理
- Android LinearLayout,RelativeLayout 简要(随记四)
- kvm qemu libvirt区别
- java文件路径几种加载方式
- 程序设计、系统开发的一些资源
- 华为面试题:交换两个数组,使得数组的和的差最小
- zzulioj--1825-- 会长爱数学(模拟)
- Android-Migrating to WebView in Android 4.4
- TimePickerDialog控件的使用
- Spring分布式事务在service中动态切换数据源