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. 查询hadoop参数变量

    [hadoop@master hadoop]$ hive -S -e 'set -v'|grep querylog|grep -E -v 'CLASSPATH|class'hive.querylog. ...

  2. 常用linq语法

    1.简单的linq语法 var ss = from r in db.Am_recProScheme select r; var ss1 = db.Am_recProScheme; string sss ...

  3. codeforces#512 Div2

    pre过了三题 终测又挂了一题 又掉分了 真的是 太菜了 A-In Search of an Easy Problem 水题 有一个1就是hard #include <bits/stdc++.h ...

  4. Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure stylesheet 非全站https

    Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure ...

  5. s3对象存储

    bkstorages 模块帮助你在蓝鲸应用中使用多种文件存储服务作为后端,用于加速静态资源,管理用户上传文件. 自定静态文件 storage 如果通过修改配置文件满足不了你的需求,你随时可以通过继承 ...

  6. 关于volatile 最完整的一篇文章

    你真的了解volatile关键字吗? 一.Java内存模型 想要理解volatile为什么能确保可见性,就要先理解Java中的内存模型是什么样的. Java内存模型规定了所有的变量都存储在主内存中.每 ...

  7. 大话https演化过程(对称加密、非对称加密、公钥、私钥、数字签名、数字证书)

    大话https演化过程(包括概念:对称加密.非对称加密.公钥.私钥.数字签名.数字证书.https访问全过程)   在网络上发送数据是非常不安全的,非常容易被劫持或是被篡改,所以每次定向发送数据你都可 ...

  8. python多线程为什么不能利用多核cpu

    GIL 与 Python 线程的纠葛 GIL 是什么东西?它对我们的 python 程序会产生什么样的影响?我们先来看一个问题.运行下面这段 python 程序,CPU 占用率是多少? # 请勿在工作 ...

  9. 使用Markdown写博客

    初识Markdown Markdown是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿这广泛使用.Markdown的设计目标是「易读易写」,语法十分简单,常用的标记符号不超 ...

  10. 53. Maximum Subarray(动态规划 求最大子数组)

      Find the contiguous subarray within an array (containing at least one number) which has the larges ...