码迷,mamicode.com
首页 > 其他好文 > 详细

hdu----149850 years, 50 colors(最小覆盖点)

时间:2014-08-22 12:17:36      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   

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 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.

bubuko.com,布布扣
 

 

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
 

 

Author
8600
 

 

Source
 

 

Recommend
 
看了好几遍愣是没看懂题目什么意思....
看了别人的题解才懂这道题要我们干啥。
bubuko.com,布布扣
 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

 

hdu----149850 years, 50 colors(最小覆盖点),布布扣,bubuko.com

hdu----149850 years, 50 colors(最小覆盖点)

标签:des   style   blog   http   color   java   os   io   

原文地址:http://www.cnblogs.com/gongxijun/p/3928738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!