hdu1498 50 years, 50 colors --- 最小点覆盖
给一个矩阵,里面有一些不同颜色的气球。每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的。
那么思路就是,对每一种颜色的气球求最小点覆盖。>k 则为答案。
相当于 poj3041的加强版,由于矩阵中不是每个点都是等价的。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
const int maxn=105;
using namespace std; int mx[maxn],my[maxn],vis[maxn],e[maxn][maxn],n,cnt,mp[maxn][maxn],mat[maxn],ans[maxn];
map<int,int> mmp; int path(int i)
{
int j;
for(j=0;j<n;j++)
{
if(e[i][j]&&!vis[j])
{
vis[j]=1;
if(my[j]==-1||path(my[j]))
{
mx[i]=j;
my[j]=i;
return 1;
}
}
}
return 0;
} int hungry()
{
int res=0;
memset(mx,-1,sizeof mx);
memset(my,-1,sizeof my);
for(int i=0;i<n;i++)
{
if(mx[i]==-1)
{
memset(vis,0,sizeof vis);
res+=path(i);
}
}
return res;
} int main()
{
int k,i,j,m,p,x;
while(scanf("%d%d",&n,&k)&&(n||k))
{
cnt=1;
mmp.clear();
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&mp[i][j]);
if(mmp[mp[i][j]]) continue;
else
{
mmp[mp[i][j]]=cnt;
mat[cnt++]=mp[i][j];
}
}
m=0;
for(p=1;p<cnt;p++)
{
x=mat[p];
memset(e,0,sizeof e);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(mp[i][j]==x) e[i][j]=1;
if(hungry()>k) ans[m++]=x;
}
if(m==0) printf("-1\n");
else
{
sort(ans,ans+m);//wa了一次。 。
printf("%d",ans[0]);
for(i=1;i<m;i++)
printf(" %d",ans[i]);
puts("");
}
}
return 0;
}
hdu1498 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 ...
- 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(二分匹配_匈牙利算法)
题目链接: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 ...
- POJ 2226 最小点覆盖(经典建图)
Muddy Fields Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8881 Accepted: 3300 Desc ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- linux grub
grub 是目前使用最广泛的linux引导装载程序,旧的lilo这个引导装载程序很少见了,grub优点: 支持较多哦的文件系统,可以使用grub主程序在文件系统中查找内核文件名 启动的时候,可以自行编 ...
- Treap树
Treap树算是一种简单的优化策略,这名字大家也能猜到,树和堆的合体,其实原理比较简单,在树中维护一个"优先级“,”优先级“ 采用随机数的方法,但是”优先级“必须满足根堆的性质,当然是“大根 ...
- WCF基礎
參考:http://www.cnblogs.com/MeteorSeed/archive/2012/04/24/2399455.html http://www.cnblogs.com/scy25114 ...
- [TL-WR841N V5~V9] 如何当作无线交换机使用?
http://service.tp-link.com.cn/detail_article_1034.html
- pku3663 Costume Party
http://poj.org/problem?id=3663 二分查找 #include <stdio.h> #include <stdlib.h> ]; int bs(int ...
- 轻松学习Linux之内核编译
欢迎大家给我投票: http://2010blog.51cto.com/350944 650) this.width=650;" onclick='window.open("h ...
- Labview中定时函数之间的区别
第一个定时函数(时间延迟):在VI中插入时间延迟,指定在运行调用VI之前延时的秒数.默认值为1.000. 第一个定时函数(等待(ms)):等待指定长度的毫秒数,并返回毫秒计时器的值.该函数进行异步系统 ...
- 清除SQL Management Studio记住的用户名和密码
SQL Server Management Studio 2008 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\Micr ...
- SQL Server sql 操作
1.重命名表将表OLD重命名为NEW: EXEC sp_rename 'OLD','NEW' 2.重命名列将表table1中的列old重命名为new: EXEC sp_rename 'table1.o ...
- myeclipse 8.5安装freemarker插件方法
1. 下载freemarker最新版本,目前本人下载时最新版本是:freemarker-ide-0.9.14.zip, ide版本的freemarker.jar版本太低,可以替换成高级版本,并修改me ...