years, ColorsTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 2309 Accepted Submission (s): 1299problem 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'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 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
Sample Output
-1 1 2 1 2 3 4 5-1
Test instructions, give the n*n matrix, each point on a balloon, color some different, for each color can play k times, each can be knocked out of a row or a column of the same color of the ball. If it can be eliminated, do not output, or the color of the output balloon, if all finished output-1
Match the X coordinate with the Y coordinate;
#include <stdio.h> #include <string.h> int g[110][110],n,pei[110],vis[110];
int find (int x,int c) {for (int i=0;i<n;i++) {if (G[x][i]==c&&!vis[i]) {vis[i]=1; if (pei[i]==-1| |
Find (Pei[i],c)) {pei[i]=x;
return 1;
}}} return 0;
} int Maxmatch (int c) {int i;
int cnt=0;
memset (Pei,-1,sizeof (PEI));
for (i=0;i<n;i++) {memset (vis,0,sizeof (VIS));
if (find (i,c)) cnt++;
} return CNT;
} int main () {int i,j,c,k;
while (scanf ("%d%d", &n,&k), N) {memset (g,0,sizeof (g));
for (i=0;i<n;i++) for (j=0;j<n;j++) scanf ("%d", &g[i][j]);
int flag=1;
for (c=1;c<=50;c++) {int max=maxmatch (c);
if (max>k) {if (flag) {flag=0;
printf ("%d", c);
} else printf ("%d", c);
}} if (flag) printf ("-1");
printf ("\ n");
} return 0; }