Years, colors |
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) |
Total submission (s): 137 Accepted Submission (s): 86 |
|
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'll be a game named "Crashing Color Balloons".
There'll is a n*n matrix board on the ground, and each grid would have a color balloon in it. and the color of the ballon is 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 both balloons with the same color belong to The same kind. What's more, each time you can is choose a single row or column of balloon, and crash the balloons that with the color Y Ou had chosen. Of course, a lot of students is 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 are impossible to being all crashed by a student in K times.
|
Inputthere'll be multiple input cases. Each test case begins with the integers n, K. N is the number of rows and columns of the balloons (1 <= n <=), a nd k is the Times, 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. |
Outputfor each test case, print in ascending order all the colors of which is impossible to being crashed by a student in K Times. If There is no choice, print "-1". |
Sample Input1 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 |
Author8600 |
Source "2006 Campus cultural activity Month" of "School Anniversary Cup" College students Program Design Competition and Hangzhou University of Engineering fourth session of college students Program design contest |
Recommendll |
/*give you a n*n lattice matrix in each box is a color of the balloon, and now you have a k chance, each time you choose a color, and then in the selection of a row, or a column, this line or the column of this color balloon all broken, K operations will not be broken balloon yasuteru from small to large sequence output, If not on the output-1 first idea: the color and edge conversion to two, and then the binary map matching, the minimum coverage point, that is, the maximum match, each color of the maximum matching of the number of sides assumed that all the edges of the K-times are rows, or are columns*/#include<bits/stdc++.h>using namespacestd;intn,k;intvis[ -];//To record the color that appeared.intcolor;/*********************** binary matching template **************************/Const intmaxn= +;intG[MAXN][MAXN];//the number is 0~n-1.intLINKER[MAXN];//Record the matching point of match point I whovector<int>v;BOOLUSED[MAXN];BOOLDfsintColorintU//look back and see if we can make a match by breaking up{ intv; for(v=1; v<=n;v++) if(g[u][v]==color&&!Used[v])//If there is this edge, and this side has not been used{Used[v]=true; if(linker[v]==-1|| DFS (Color,linker[v]))//If the point does not match and you can find a match, you can use this edge as the match point .{Linker[v]=u; return true; } } return false; } intHungaryintColor//returns the maximum number of matches{ intres=0; intu; MEMSET (linker,-1,sizeof(linker)); for(u=1; u<=n;u++) {memset (used,0,sizeof(used)); if(Dfs (COLOR,U))//If this point has a matching pointres++; } returnRes; }/*********************** binary matching template **************************/intMain () {//freopen ("In.txt", "R", stdin); while(SCANF ("%d%d", &n,&k)!=eof&& (n+k)) {memset (g,0,sizeofg); memset (Vis,0,sizeofvis); V.clear (); for(intI=1; i<=n;i++){ for(intj=1; j<=n;j++) {scanf ("%d",&color); if(vis[color]==0) {Vis[color]=1; } G[i][j]=color; } } for(intI=1; i<= -; i++){ if(Vis[i]) {//This color has been used. if(Hungary (i) >k)//which means the color can't be erased.V.push_back (i); } } if(v.size () = =0) printf ("-1\n"); Else{ for(intI=0; I<v.size (); i++) {printf (i==0?"%d":"%d", V[i]); } printf ("\ n"); } } return 0;}
Years, colors