50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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
枚举每个点,建模,套板子;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<" "<<endl;
const int N=1e2+,M=1e6+,inf=2e9+,mod=1e9+;
const ll INF=1e18+;
int n,m,q;
int a[N][N];
int mp[N][N];
int linker[N];
bool used[N];
bool dfs(int a)
{
for(int i=;i<n;i++)
if(mp[a][i]&&!used[i])
{
used[i]=true;
if(linker[i]==-||dfs(linker[i]))
{
linker[i]=a;
return true;
}
}
return false;
}
int hungary()
{
int result=;
memset(linker,-,sizeof(linker));
for(int i=;i<n;i++)
{
memset(used,,sizeof(used));
if(dfs(i)) result++;
}
return result;
}
int slove(int f,int x)
{
int cnt=;
memset(mp,,sizeof(mp));
for(int i=;i<=f;i++)
{
for(int j=;j<=f;j++)
{
if(a[i][j]==x)
{
cnt++;
mp[i-][j-]=;
}
}
}
if(cnt<=q)return ;
int kill=hungary();
if(kill<=q)return ;
return ;
}
int flag[];
vector<int>ans;
int main()
{
while(~scanf("%d%d",&n,&q))
{
if(n==&&q==)break;
ans.clear();
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
scanf("%d",&a[i][j]);
}
for(int i=;i<=;i++)
{
if(!slove(n,i))
ans.push_back(i);
}
if(ans.size()==)
printf("-1\n");
else
{
printf("%d",ans[]);
for(int i=;i<ans.size();i++)
printf(" %d",ans[i]);
printf("\n");
}
}
return ;
}

hdu 1498 50 years, 50 colors 最小点覆盖的更多相关文章

  1. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

  2. hdu1498 50 years, 50 colors --- 最小点覆盖

    给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...

  3. HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)

    d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...

  4. hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...

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

  6. HDU——1498 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. HDU 1498 50 years, 50 colors

    题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...

  8. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  9. 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. mysql数据类型及存储过程

    转自:http://www.cnblogs.com/mark-chan/p/5384139.html 存储过程简介 SQL语句需要先编译然后执行,而存储过程(Stored Procedure)是一组为 ...

  2. 160226、js常用的验证

    /*** 特殊符号 */ function specialCharacter(carNo){ var st=/^[^/@#$%^&*()—''_()!¥~·..,-<><&g ...

  3. poj1952 BUY LOW, BUY LOWER【线性DP】【输出方案数】

    BUY LOW, BUY LOWER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:11148   Accepted: 392 ...

  4. Oracle卸载之linux快速卸载rac脚本-一键卸载

    #!/bin/bash#Usage:Log on as the superuser('root') on node1,node2 cd /u01/app/11.2.0/grid/bin./crsctl ...

  5. Oracle性能优化之表压缩及并行提高效率的测试

    1.制作测试表 create table t1 as select * from FW_T_GTXLOG insert into t1 select * from t1; create table t ...

  6. socket协议和http协议性能对比

    最近做了一次队列服务的性能测试,是通过两种协议windows socket和http分别往内存中写入url.对比哪种协议的效果更高,下图是测试结果.此次使用的工具是loadrunner.在压socke ...

  7. python面向对象(类和对象及三大特性)

    类和对象是什么 创建类 新式类 和 经典类 面向对象三大特性 继承 封装 多态   面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...

  8. 第1章 1.7计算机网络概述--理解OSI参考模型分层思想

    OSI七层模型,知识参考理论. 分层标准的好处: 1.不同的硬件生产商生产的硬件产品,连通后就可以用了,有助于互联网发展. 2.分层,分成不同的模块,某一层的变化,不会影响其他层.如:IPv4改为IP ...

  9. mysql 数据操作 单表查询

    单表查询的语法 distinct 去重 SELECT 字段1,字段2... FROM 表名 库.表名 WHERE 条件 过滤 符合条件的 GROUP BY field 分组条件 HAVING 筛选 过 ...

  10. OpenS-CAD学习(1)

    1.OpenS-CAD是一个不错的小巧的开源程序,以图层方式组织图形,可以绘制基本的线段.弧段.圆,可以进行节点对象捕捉,可以选择几何对象.对图幅进行平移.放大.缩小.可以将结果序列化保存为xml格式 ...