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 则为 ...
随机推荐
- 翻译 | 玩转 React 表单 —— 受控组件详解
原文地址:React.js Forms: Controlled Components 原文作者:Loren Stewart 译者:小 B0Y 校对者:珂珂君 本文涵盖以下受控组件: 文本输入框 数字输 ...
- GitHub使用(三) - GitHub安装及初步使用
1. 首先下载Windows版本“GitHubSetup.exe”如下,下载地址为:https://desktop.github.com/
- 使用 Dawn 构建 React 项目
开发一个 React 项目,通常避免不了要去配置 Webpack 和 babel 之类,以支持 commonjs 或 es 模块及各种 es 新语法,及及进行 jsx 语法的转义.当然也可以用 cre ...
- M方法
ThinkPHP函数详解:M方法 M方法用于实例化一个基础模型类,和D方法的区别在于:1.不需要自定义模型类,减少IO加载,性能较好:2.实例化后只能调用基础模型类(默认是Model类)中的方法:3. ...
- django之快速分页
本文介绍djanog两种分页,第一是普通分页,第二是使用haystack全文检索的分页. 1.django自带分页功能,这个功能非常好用.基本知识点:Django提供了数据分页的类,这些类被定义在dj ...
- VB.net DateTimePicker 初始化为空,选择后显示日期
目的:当某记录的日期数据为空的时候,DateTimePicker 不以默认当前时间显示. 优点:避免不规则的时间格式输入:符合平时遇到的时间输入习惯 缺点:设置要代码,没有textbox控件那么方便设 ...
- 访问 IIS 元数据库失败
问题: 访问 IIS 元数据库失败.说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.Web ...
- 启用事务操作,解决批量插入或更新sqlite,mssql等数据库耗时问题
private void button1_Click(object sender, EventArgs e) { //Sqlite使用事务批量操作 极大的提高速度 DateTime starttime ...
- PHP多进程编之僵尸进程问题
上一篇说到了使用pcntl_fork函数可以让PHP实现多进程并发或者异步处理的效果.那么问题是我们产生的进程需要去控制,而不能置之不理.最基本的方式就是fork进程和杀死进程. 通过利用pcntl_ ...
- (10.11)Java第一小步
在度过大一和大二浑浑噩噩的咸鱼生活之后,我决定 开始为自己的未来负责,开始学习自己喜欢的Java,同时决定以这篇博客来开启自己的博客之旅和Jaca的学习之路. 以后我也会陆续在博客园更新自己的博客,记 ...