50 years, 50 colors
50 years, 50 colors |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
| Total Submission(s): 137 Accepted Submission(s): 86 |
|
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 |
|
Sample Output
-1 |
|
Author
8600
|
|
Source
“2006校园文化活动月”之“校庆杯”大学生程序设计竞赛暨杭州电子科技大学第四届大学生程序设计竞赛
|
|
Recommend
LL
|
/*
给你一个n*n的格子矩阵每个格子中都存放着一种颜色的气球,现在你有k次机会,每次选择一中颜色,然后在选择一行,或者一列,将这行或这列的这种颜色
的气球全部踩破,k次操作之后将没有踩破的气球安照从小到大的顺序输出,如果没有就输出-1 初次思路:将颜色和边转化为二分图,然后进行二分图匹配,求最小覆盖点,也就是最大匹配,每种颜色的最大匹配的边数
假设所有的边选取的k次的边都是行,或者都是列 */
#include<bits/stdc++.h>
using namespace std;
int n,k;
int vis[];//记录那种颜色出现过
int color;
/***********************二分匹配模板**************************/
const int MAXN=;
int g[MAXN][MAXN];//编号是0~n-1的
int linker[MAXN];//记录匹配点i的匹配点是谁
vector<int>v;
bool used[MAXN];
bool dfs(int color,int u)//回溯看能不能通过分手来进行匹配
{
int v;
for(v=;v<=n;v++)
if(g[u][v]==color&&!used[v])
//如果有这条边,并且这条边没有用过
{
used[v]=true;
if(linker[v]==-||dfs(color,linker[v]))//如果这个点没有匹配过,并且能找到匹配点,那么就可以以这个边作为匹配点
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary(int color)//返回最大匹配数
{
int res=;
int u;
memset(linker,-,sizeof(linker));
for(u=;u<=n;u++)
{
memset(used,,sizeof(used));
if(dfs(color,u))//如果这个点有匹配点
res++;
}
return res;
}
/***********************二分匹配模板**************************/
int main(){
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&k)!=EOF&&(n+k)){
memset(g,,sizeof g);
memset(vis,,sizeof vis);
v.clear();
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%d",&color);
if(vis[color]==){
vis[color]=;
}
g[i][j]=color;
}
} for(int i=;i<=;i++){
if(vis[i]){//这种颜色用过了
if(hungary(i)>k)//说明这种颜色不可能被消掉
v.push_back(i);
}
}
if(v.size()==)
printf("-1\n");
else{
for(int i=;i<v.size();i++){
printf(i==?"%d":" %d",v[i]);
}
printf("\n");
}
}
return ;
}
50 years, 50 colors的更多相关文章
- HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...
- hdu 1498 50 years, 50 colors 最小点覆盖
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...
- HDU——1498 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...
- HDU——T 1498 50 years, 50 colors
http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
题目:点击打开链接 题意:每个格子有不同颜色的气球用不同数字表示,每次可选某一行 或某一列来戳气球.每个人有K次机会.求最后哪些气球不能在 k次机会内 ...
- HDU 1498:50 years, 50 colors(二分图匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
- hdu1498 50 years, 50 colors --- 最小点覆盖
给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...
随机推荐
- windows10 下安装node失败 出现2502 2503的解决办法
下载node出现以下异常 : the install has encountered an unexpected errer installing this package.this may i ...
- Java开发中遇到的问题
head丢失 html的dtd不对 Integer数据类型 使用==比较 这个肯定错(事后才知道) sql语句处理分组的时候,在本地服务使用没问题,在服务器上出现sql异常 group by语句规范, ...
- 【个人笔记】《知了堂》node.js简介及创建应用
Node.js是什么? Node.js是建立在谷歌Chrome的JavaScript引擎(V8引擎)的Web应用程序框架.Node.js自带运行时环境可在Javascript脚本的基础上可以解释和执行 ...
- NET应用——使用RSA构建相对安全的数据交互
最近又被[现场破解共享单车系统]刷了一脸,不得不开始后怕:如何防止类似的情况发生? 想来想去,始终觉得将程序加密是最简单的做法.但是摩拜.ofo也有加密,为什么仍然被破解?那是因为请求在传输过程中被篡 ...
- ThinkPHP中:用户登录权限验证类
使用CommonAction.class.php公共类,统一判断用户是否登录 <?php //后台登录页 Class CommonAction extends Action{ //后台登录页面 ...
- 用css绘制各种图形
1.用css绘制三角形 http://www.cnblogs.com/blosaa/p/3823695.html
- 渣渣学QT
初学QT,自己的一些小总结,错误之处,望大神指点一二: 1,添加资源文件时想应用在界面的背景,但是发现用不了,后来才知道是没有"构建"?应该是要在构建之后才将所添加的资源文件真正的 ...
- Zabbix(二) : Zabbix Server端配置文件说明
Zabbix Server端配置文件说明 # This is a configuration file for Zabbix Server process # To get more informat ...
- ajax url参数中文乱码解决方法
较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即encodeURI(encodeURI("url的中文参数值")) JS代码: var name=&q ...
- OOP编程特性综合项目
package SourceFile; //创建动物类(父类). public abstract class CAnimal { public boolean mammal; //是不是哺乳动物 ...