50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1633 Accepted Submission(s): 891
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 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给出一个矩阵 ,里面放一些气球(用数字表示), 每次选一行或者一列, 可以打k次,,一行或一列中相同颜色的气球(相同数字)可以一下全打爆,将不能打爆的气球颜色输出,即数字,全被打爆则输出-1。。统计下每种颜色的个数,求出每种颜色的最大匹配,在与k进行比较即可#include <cstdio> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <algorithm> #include<string.h> using namespace std; int n,k,map[1010][1010]; int v[1010],xx[1010],yy[1010]; int dfs(int e,int r) { for(int i=1; i<=n; i++) { if(map[r][i]==e && !v[i]) { v[i]=1; if(yy[i]==-1 || dfs(e,yy[i])) { yy[i]=r; xx[r]=i; return 1; } } } return 0; } int pipei(int e) { memset(xx,-1,sizeof(xx)); memset(yy,-1,sizeof(yy)); int ans=0; for(int i=1; i<=n; i++) { memset(v,0,sizeof(v)); if(xx[i]==-1) { ans+=dfs(e,i); } } return ans; } int main() { while(~scanf("%d%d",&n,&k)) { if(n==0 && k==0) break; int b[55]; memset(map,0,sizeof(map)); memset(b,0,sizeof(b)); int i,j; for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { scanf("%d",&map[i][j]); } } int m=0; int flag=1; for(i=1; i<=50; i++) { if(k<pipei(i)) { b[m++]=i; flag=0; } } if(flag) printf("-1\n"); else { for(i=0; i<m; i++) { if(b[i]!=0) { if(i==0) printf("%d",b[i]); else printf(" %d",b[i]); } } printf("\n"); } } return 0; }