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升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
随机推荐
- ps闪闪发光的字 教程+自我练习
本教程的文字效果非常经典.不仅是效果出色,创作思路及制作手法都堪称完美.作者并没有直接使用纹理素材,纹理部分都是用滤镜来完成.这需要很强的综合能力,非常值得学习和借鉴.最终效果 我的: 1.创建一个新 ...
- Embedded之Introduction
1 Embedded system An embedded system is a combination of computer hardware and software, and perhaps ...
- 实现JQuery EasyUI右键菜单变灰不可用效果
使用过EasyUI的朋友想必都知道疯狂秀才写的后台界面吧,作为一个初学者我不敢妄自评论它的好坏,不过它确实给我们提供了一个很好框架,只要在它的基础上进行修改,基本上都可以满足我们开发的需要. 知道“疯 ...
- bzoj3714: [PA2014]Kuglarz
[PA2014]KuglarzTime Limit: 20 Sec Memory Limit: 128 MBSubmit: 553 Solved: 317[Submit][Status][Discus ...
- 《Java数据结构与算法》笔记-CH4-6栈结构实现中缀转后缀
/** * 中缀表达式转换成后缀表达式: 从输入(中缀表达式)中读取的字符,规则: 操作数: 写至输出 左括号: 推其入栈 右括号: 栈非空时重复以下步骤--> * 若项不为(,则写至输出: 若 ...
- ZOJ-3686 A Simple Tree Problem 线段树
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686 题意:给定一颗有根树,每个节点有0和1两种值.有两种操作: ...
- 一排下去再上来的div
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- js获取时间搓
var oData=new Date().getTime(2016-01-16); console.log(oData);
- Nginx下Redmine2.6配置
Apache下Redmine2.6配置,请参考:http://blog.linuxeye.com/405.html CentOS6.6下安装Redmine2.6+MySQL5.6+Nginx,教程如下 ...
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)
原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...