50 years, 50 colors
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1516 accepted submission (s): 818
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.
Inputthere 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.
Outputfor 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 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 3 43 350 50 5050 5050 500 0
Sample output
-1121 2 3 4 5-1
Question: During the celebration, there are N * n grids with different colors of balloons in them, so that students can take the balloon, however, one student can only take one row or one column of balloons of the same color at a time, and one student can only take a video K times at most. If they cannot be completed in 4 K times, the color of the balloon is output, in ascending order. If not, output-1.
Problem solving: It seems like we can't start with it, but according to the question, we can split the balloons of different colors and find each type of balloon each time. This is a problem of minimum coverage.
# Include <stdio. h> # include <string. h> int map [55] [105] [105], vist [105], Match [105], n; int find (int I, int C) {for (Int J = 1; j <= N; j ++) if (! Vist [J] & map [C] [I] [J]) {vist [J] = 1; if (Match [J] = 0 | find (Match [J], c) {match [J] = I; return 1 ;}} return 0 ;} int main () {int M, C, CC [55]; while (scanf ("% d", & N, & M)> 0 & N + M! = 0) {memset (MAP, 0, sizeof (MAP); memset (CC, 0, sizeof (CC); For (INT I = 1; I <= N; I ++) for (Int J = 1; j <= N; j ++) {scanf ("% d", & C ); map [C] [I] [J] = 1; CC [c] = 1;} int flag = 0, ans; For (INT c = 1; C <= 50; c ++) if (CC [c]) {ans = 0; memset (match, 0, sizeof (MATCH); For (INT I = 1; I <= N; I ++) {memset (vist, 0, sizeof (vist); ans + = find (I, C);} If (ANS> m) {If (FLAG) printf (""); printf ("% d", c); flag = 1 ;}}if (flag = 0) printf ("-1 "); printf ("\ n ");}}