50 years, 50 colors
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.
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
-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 ",res[num-1]); } } return 0; }