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 ...
随机推荐
- C# 如何以参数的形式调用.exe程序
System.Diagnostics.Process.Start("程序的路径", "参数1 参数2");第一个参数是aaa.exe 的路径,第二个参数是用空格 ...
- 《C++ primer》--第11章
习题11.1 algorithm头文件定义了一个count的函数,其功能类似于find.这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果.编写程序读取一系列int型数据,并将它们存储 ...
- Delphi RichEx 图像
unit RichEx; {2005-03-04 LiChengbinAdded:Insert bitmap or gif into RichEdit controls from source fil ...
- codeforces 260 div2 C题
C题就是个dp,把原数据排序去重之后得到新序列,设dp[i]表示在前i个数中取得最大分数,那么: if(a[i] != a[i-1]+1) dp[i] = cnt[a[i]]*a[i] + dp[ ...
- acdream 1044
题意:有你一个草坪,草的初始高度都是100,让你用割草机割,割草机只能横着或竖着割,每次割的高度一定,问你能不能割出给定的草坪出来. 考虑任意一个草被割要么是横着要么竖着,所以任意一个草必然是它所在行 ...
- nodejs 5.2.0文档自翻译——HTTP模块
HTTP Class: http.Agent new Agent([options]) agent.destroy() agent.freeSockets agent.getName(options) ...
- python日志输出
import logging logger = logging.getLogger() #生成一个日志对象,()内为日志对象的名字,可以不带,名字不给定就是root,一般给定名字,否则会把其他的日志输 ...
- 【转】使用JavaScriptCore在JS和OC间通信
http://www.cocoachina.com/ios/20160623/16796.html iOS 开发中,我们时不时的需要加载一些 Web 页面,一些需求使用 Web 页面来实现可以更可控, ...
- HDU 5763 Another Meaning (kmp + dp)
Another Meaning 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 Description As is known to all, ...
- POJ 2253 Frogger (dijkstra 最大边最小)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...