HDU——1498 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): 2683 Accepted Submission(s): 1538
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.

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
1
2
1 2 3 4 5
-1
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 110
using namespace std;
bool vis[N],vist[N];
int n,k,sum,tot,ans[N],girl[N],a[N][N],map[N][N];
int read()
{
,f=; char ch=getchar();
; ch=getchar();}
+ch-'; ch=getchar();}
return x*f;
}
int find(int x)
{
;i<=n;i++)
{
if(!vis[i]&&map[x][i])
{
vis[i]=true;
||find(girl[i])) {girl[i]=x; ;}
}
}
;
}
int col()
{
;
memset(girl,-,sizeof(girl));
;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(find(i)) s++;
}
return s;
}
void begin()
{
sum=,tot=;
memset(a,,sizeof(a));
memset(ans,,sizeof(ans));
memset(vist,,sizeof(vist));
}
int main()
{
)
{
n=read(),k=read();
&&k==) break;
begin();
;i<=n;i++)
;j<=n;j++)
a[i][j]=read();
;i<=n;i++)
;j<=n;j++)
if(!vist[a[i][j]])
{
vist[a[i][j]]=true;
memset(map,,sizeof(map));
;u<=n;u++)
;v<=n;v++)
if(a[u][v]==a[i][j])
map[u][v]=;
if(col()>k) ans[++sum]=a[i][j];
}
) {printf("-1\n"); continue;}
sort(ans+,ans++sum);
;i<sum;i++) printf("%d ",ans[i]);
printf("%d\n",ans[sum]);
}
;
}
HDU——1498 50 years, 50 colors的更多相关文章
- 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 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 ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Hdu 1498 二分匹配
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1498(最小点覆盖集)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 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 ...
- 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 1498:50 years, 50 colors(二分图匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...
随机推荐
- Swift 基础语法入门(一)
一.变量和常量 1.声明常量和变量 用let来声明常量 let radius = 10 用var来声明变量 var age = 20 或者是var x = 0.0, y = 0.0, z = 0 ...
- 设计模式之一:strategy pattern
定义算法族,彼此之间可以替换.变化的方法抽出封装,不变的父类定义继承.多用组合少用继承. 代码示例先不贴了.
- hexo_config.yml配置内容
# Hexo Configuration ## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/ ...
- 程序员容易忽略的SQL Server错误集锦
1.大小写 大写T-SQL 语言的所有关键字都使用大写,规范要求. 2.使用“;” 使用“;”作为 Transact-SQL 语句终止符.虽然分号不是必需的,但使用它是一种好的习惯,对于合并操作MER ...
- 实训day01 python基础
一.编程语言 编程语言:可以被计算机所识别的表达方式. 编程:程序员通过编程语言将自己的想法编写出来,产生的结果就是包含字符的文件. 其中,只有程序在运行时,其中的字符才有特定的语法意义. 二.计算机 ...
- freenas iscsi initiator 配置
1.加载Iscsi Initiator 模块 freebsd从7.0开始已经包含了Iscsi Initiator ,不需要安装后再使用,但在使用前,需要加载模块. # kldload -v iscsi ...
- error while loading shared libraries: libclntsh.so.11.1
解决这个问题有两种方法 1.在当前用户下,添加链接库所在路径 LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_ ...
- ArrayList中removeAll和clear的区别(无区别)
removeAll会直接调用此方法,传入list和false,因中间的逻辑都不会走(如果由retainAll方法调用,则会走这些逻辑判断),所以只需要看finaly中的最后一个if条件,w=0,通过循 ...
- 关于js事件冒泡和事件捕获
事件捕获指的是从document到触发事件的那个节点,即自上而下的去触发事件.相反的,事件冒泡是自下而上的去触发事件.绑定事件方法的第三个参数,就是控制事件触发顺序是否为事件捕获.true,事件捕获: ...
- Mysql对象
2.简介 2.1 存储过程 2.1.1什么是存储过程 存储过程就是一种类似函数的脚本,可以把多个sql语句组合起来,然后使用 call 存储过程名 来调用,从而执行这些SQL语句. 特点:一次编译,下 ...