hdu----149850 years, 50 colors(最小覆盖点)
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.
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
“2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛
Recommend
看了好几遍愣是没看懂题目什么意思....
看了别人的题解才懂这道题要我们干啥。
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("%dn",res[num-1]);
73 }
74 }
75 return 0;
76 }
- hadoop系列之深入优化
- Using sqlite with .NET
- Gridview行上下移动自己做的一个小例子(第一种方法)
- Hadoop伪分布式集群安装部署
- sql 表有没有自增列,插入自增列值
- jsp中的JSTL与EL表达式用法及区别(二)
- WPF 给控件添加复制事作
- wpf RoutedUICommand 绑定
- jsp中的JSTL与EL表达式用法及区别(一)
- java线程池模型
- lock小记
- HTML布局的基本要点
- Building a Middle Tier Component using NHibernate and Spring.NET
- Linq 和DefaultView两种方法去掉DataTable 里的重复行
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- webpack实战——生产环境配置【上】
- 深度阅读之《Concurrency in Go》
- 为了不让代码看起来像一坨* 我在工作中反复用了这个
- 在 Go 语言中 Patch 非导出函数
- SpringCloud 配置中心服务端配置解析流程分析
- Qt多线程编程之线程池
- PWN:Tcache Attack原理
- [Go]GO语言实战-GO-FLY在线客服cobra库命令行参数解析
- [Go]GO语言实战-GO-FLY在线客服gorm导入sql文件
- Day7.数据类型-集合
- 详解一条查询select语句和更新update语句的执行流程
- JSP 开发环境搭建与项目运行(二)
- Activity启动时生命周期汇总
- 「程序员」Flutter:从网络获取数据遇到的坑
- 程序员:拿到新电脑如何配置Git环境