HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors
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.

color of the ballon in the i row, j column.Input ends with n = k = 0.
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
-1
1
2
1 2 3 4 5
-1
有这样一个矩阵,矩阵里面是气球。气球有颜色编号1-50,询问在k次之内能不能把同种颜色存在的气球消掉(每次询问有K次机会),超过K此的气球编号,储存起来,并按编号按升序输出。
题意不是非常好理解,可是看明确之后,就非常清晰了
求最小点覆盖——即 用最少的点覆盖图中最多的边。
依次枚举就能够
矩阵的一维下标 当做 X集合,二维下标当做Y集合,询问全部点的最大匹配,比K大自然不满足
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#define init(a) memset(a,0,sizeof(a))
#define PI acos(-1,0)
using namespace std;
const int maxn = 110;
const int maxm = 100001;
#define lson left, m, id<<1
#define rson m+1, right, id<<1|1
#define min(a,b) (a>b)?b:a
#define max(a,b) (a>b)?a:b
const int N = 50010;
int ma[maxn][maxn];
int line[maxn],res[maxn];
bool vis[maxn],bj[maxn];
int k,n,m,t;
int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
int DFS(int st,int u)
{
for(int v = 1;v<=n;v++)
{
if(ma[u][v]== st && !vis[v])
{
vis[v] = 1;
if(line[v]==-1 || DFS(st,line[v]))
{
line[v] = u;
return 1;
}
}
}
return 0;
}
int K_M(int st)
{
memset(line,-1,sizeof(line));
int ans = 0;
for(int i = 1;i<=n;i++)
{
init(vis);
ans += DFS(st,i);
}
return ans;
}
int main()
{
int t;
while(~scanf("%d%d",&n,&k))
{
if(n==0 && k== 0) break;
init(ma); init(res); init(bj);
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
scanf("%d",&t);
ma[i][j] = t;
if(!bj[t])
bj[t] = 1;
}
}
int cnt,num = 0;
for(int i = 1;i<=55;i++)
{
if(bj[i])
{
cnt = K_M(i);
(cnt>k)?(res[num++] = i):(1);
}
}
if(num==0) puts("-1");
else
{
//sort(res,res+num);
qsort(res,num,sizeof(res[0]),cmp);
for(int j = 0;j<num-1;j++)
printf("%d ",res[j]);
printf("%d\n",res[num-1]);
}
}
return 0;
}
HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)的更多相关文章
- hdu 1498 50 years, 50 colors 最小点覆盖
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu1498 50 years, 50 colors --- 最小点覆盖
给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- 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 ...
- HDU 1498 50 years, 50 colors
题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...
- hdu 1498(最小点覆盖集)
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) ...
随机推荐
- Eclipse用法和技巧二十:一个快速打印技巧
调试的时候经常用到打印语句,当需要添加的说明字符串和需要打印的数值混淆到一起的时候,需要先写字符串如,"the string here is",接着再输入变量的值.这样一来一去还是 ...
- Microsoft.AspNetCore.Routing路由
Microsoft.AspNetCore.Routing路由 这篇随笔讲讲路由功能,主要内容在项目Microsoft.AspNetCore.Routing中,可以在GitHub上找到,Routing项 ...
- 面试中关于Java中涉及到知识点(转)
本篇文章会对面试中常遇到的Java技术点进行全面深入的总结,帮助我们在面试中更加得心应手,不参加面试的同学也能够借此机会梳理一下自己的知识体系,进行查漏补缺. 1. Java中的原始数据类型都有哪些, ...
- Charles_N:HTTP请求响应监听工具
Charles:HTTP请求响应监听工具使用说明.doc 1. 介绍 Charles是一个HTTP代理服务器,HTTP监视器,反转代理服务器.它允许一个开发者查看所有连接互联网的HTTP通信 ...
- iOS "The sandbox is not in sync with the Podfile.lock"解决方式
更新Cocoapod之后出现故障: diff: /../Podfile.lock: No such file or directory diff: Manifest.lock: No such fil ...
- Web端server推送技术原理分析及dwr框架简单的使用
1 背景 "server推送技术"(ServerPushing)是近期Web技术中最热门的一个流行术语.它是继"Ajax"之后又一个倍受追捧的Web技术.&qu ...
- <1> perl概述
[root@wx03 1]# cat a1.pl $arr=[1,2,3,4,5,6]; print $arr->[4]."\n"; $hash={a=>1,b=> ...
- hdu4707 Pet
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...
- JavaScript快速入门(五)——表达式运算
赋值运算 赋值运算的形式为左值 = 右值.如果同个表达式中有多个赋值运算,则从右到左运算.例如: a = b = c; // 和下面两行等价 b = c; a = b; 另外一种赋值运算的形式叫做复合 ...
- 手机字段存储报错 :Warning Code : 1264 Out of range value for column 'buyer_tpl' at row 1
企鹅上朋友问我: 我这明明是11位的int 为啥还说超出范围了呢,然后发来报警截图 我看到是 buyer_tpl int(13) unsigned NOT NULL,就知道是怎么回事了,打开dev. ...