50 years, 50 colors
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1695 accepted submission (s): 931
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 input1 112 11 11 22 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
Author8600
Source "2006 campus cultural activity month"-"celebration Cup" College Students' Program Design Competition and the fourth college students' Program Design Competition of Hangzhou University of Electronic Science and Technology
The recommend has read the question several times and does not understand the meaning of the question... only after reading other people's question solutions can we understand what this question means.
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 const int maxn = 110; 5 int ma[maxn][maxn]; 6 int line[maxn],res[maxn]; 7 bool vis[maxn],bj[maxn]; 8 int k,n,m,t; 9 template <class T>10 void init(T a){11 memset(a,0,sizeof(a));12 }13 int match(int st,int u)14 {15 for(int v = 1;v<=n;v++)16 {17 if(ma[u][v]== st && !vis[v])18 {19 vis[v] = 1;20 if(line[v]==-1 || match(st,line[v]))21 {22 line[v] = u;23 return 1;24 }25 }26 }27 return 0;28 }29 int cmp(const void *a,const void *b){30 return *(int *)a - *(int *)b;31 }32 int K_M(int st)33 {34 memset(line,-1,sizeof(line));35 int ans = 0;36 for(int i = 1;i<=n;i++){37 init(vis);38 ans += match(st,i);39 }40 return ans;41 }42 int main()43 {44 int t;45 while(~scanf("%d%d",&n,&k))46 {47 if(n==0 && k== 0) break;48 init(ma); init(res); init(bj);49 for(int i = 1;i<=n;i++)50 {51 for(int j = 1;j<=n;j++)52 {53 scanf("%d",&t);54 ma[i][j] = t;55 if(!bj[t])56 bj[t] = 1;57 }58 }59 int cnt,num = 0;60 for(int i = 1;i<=55;i++)61 {62 if(bj[i]){63 cnt = K_M(i);64 (cnt>k)?(res[num++] = i):(1);65 }66 }67 if(num==0) puts("-1");68 else{69 qsort(res,num,sizeof(res[0]),cmp);70 for(int j = 0;j<num-1;j++)71 printf("%d ",res[j]);72 printf("%d\n",res[num-1]);73 }74 }75 return 0;76 }
View code