HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
题目:点击打开链接
题意:每个格子有不同颜色的气球用不同数字表示,每次可选某一行
或某一列来戳气球。每个人有K次机会。求最后哪些气球不能在
k次机会内被戳破。将这些气球的编号按升序输出。
分析:行列匹配,每种颜色的气球都要判断,故dfs传参时加一个气球的
编号。
感想:1、开始以为要按照最大匹配数按升序排列,昨天wa了一下午,把我搞郁闷了。
今天重新看题,是要按照id来排序。
2、学习了vector的用法,以前都不会用。。。这个之后汇总了再。。。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std; struct node
{
int id;
int cnt;
}t[55];
int g[110][110];
int match[110];
int vis[110];
int n;
vector<int> myv; bool cmp(node a,node b)
{
return a.cnt>b.cnt;
}
bool dfs(int u,int v)
{
for(int i=0;i<n;i++)
{
if(g[u][i]==v && !vis[i])
{
vis[i]=true;
if(match[i]==-1||dfs(match[i],v))
{
match[i]=u;
return true;
}
}
}
return false;
}
int main()
{
int k,i,p,flag,j;
while(scanf("%d%d",&n,&k)&&n&&k)
{
flag=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%d",&g[i][j]);
}
memset(t,0,sizeof(t));
for(p=1;p<=50;p++)
{
memset(match,-1,sizeof(match));
t[p].id=p;
for(i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i,p))
t[p].cnt++;
}
}
sort(t+1,t+51,cmp);
myv.clear();
for(j=1;j<=50;j++)
{
if(t[1].cnt<=k)
break;
flag=1;
if(t[j].cnt>k)
myv.push_back(t[j].id);
}
sort(myv.begin(),myv.end());
if(flag)
{
for(i=0;i<myv.size();i++)
printf("%d%c",myv[i],i==myv.size()-1?'\n':' ');
}
if(!flag)
printf("-1\n");
}
return 0;
}
积累:
对vector中的元素排序:
头文件#include<algorithm>
vector<int> arr;
//输入数据
sort(arr.begin(),arr.end());
HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)的更多相关文章
- hdu149850 years, 50 colors (多个最小顶点覆盖)
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- POJ 1498[二分匹配——最小顶点覆盖]
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1498] 题意:给出一个大小为n*n(0<n<100)的矩阵,矩阵中放入m种颜色(标号为1 ...
- poj2226-Muddy Fields二分匹配 最小顶点覆盖 好题
题目 给到一个矩阵,有些格子上是草,有些是水.需要用宽度为1,长度任意的若干块木板覆盖所有的水,并不能覆盖草,木板可以交叉,但只能横竖放置,问最少要多少块板. 分析 经典的矩阵二分图构图和最小点覆盖. ...
- POJ2226 Muddy Fields 二分匹配 最小顶点覆盖 好题
在一个n*m的草地上,.代表草地,*代表水,现在要用宽度为1,长度不限的木板盖住水, 木板可以重叠,但是所有的草地都不能被木板覆盖. 问至少需要的木板数. 这类题的建图方法: 把矩阵作为一个二分图,以 ...
- 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 ...
- 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)
On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...
- 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(最小点覆盖,坑称号)
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 ...
随机推荐
- .NET之美——.Net 项目代码风格要求
.Net 项目代码风格要求 PDF版下载:项目代码风格要求V1.0.pdf 代码风格没有正确与否,重要的是整齐划一,这是我拟的一份<.Net 项目代码风格要求>,供大家参考. 1. C# ...
- HDU 5878 I Count Two Three
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Hilbert先生旅馆的故事
以前上实变函数的时候稍微讲了下这个故事呢. 来自Hansschwarzkopf 很久很久以前,在欧洲某国的一个小镇上,Hilbert先生开了一家拥有无数个房间的旅馆.一天,旅馆生意红火得一塌糊涂,不到 ...
- Easy steps to create a System Tray Application with C# z
Hiding the C# application to the system tray is quiet straight forward. With a few line of codes in ...
- delphi 设置表格样式。
//设置表格样式 wordDoc.Tables.Item(1).Borders.Item(Word.WdBorderType.wdBorderLeft).LineStyle = Word.WdLine ...
- Cloudera的安装
To enable these parts of the tutorial, choose one of the following options: To use Cloudera Express ...
- Python中的__init__,__call__
__init__函数 当一个类实例被创建时, __init__() 方法会自动执行,在类实例创建完毕后执行,类似构建函数.__init__() 可以被当成构建函数,不过不象其它语言中的构建函数,它并不 ...
- python学习之self,cls,staticmethod,classmethod
一.总体说明 python类里会出现这三个单词,self和cls都可以用别的单词代替,类的方法有三种, 一是通过def定义的 普通的一般的,需要至少传递一个参数,一般用self,这样的方法必须通过一个 ...
- 瞬间从IT屌丝变大神——命名规则
为了避免命名冲突,命名规则如下: 公共组件因为高度重用,,命名从简,不要加前缀. 各栏目的相应代码,需加前缀,前缀为工程师姓名拼音的首字母,例如:海子前缀为“hz_”,分隔符为下划线"_&q ...
- 我的web前端修炼之路从此开始
看过一篇文章,上面说过要想学习一门新技术,从什么时候开始都是不晚的.但对于一名大四的学生,只会一点简单的网页架构,只懂得HTML,CSS,JavaScript简单的一点皮毛,却怎么也说不过去.但也是这 ...