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 ...
随机推荐
- 开学了!这些Linux认证你要知道。
导读 大家好,今天我们将认识一些非常有价值的全球认可的Linux认证.Linux认证是不同的Linux专业机构在全球范围内进行的认证程序.Linux认证可以让Linux专业人才可以在服务器领域或相关公 ...
- [Everyday Mathematics]20150122
设 $f:[0,1]\to [0,1]$. (1). 若 $f$ 连续, 试证: $\exists\ \xi\in [0,1],\st f(\xi)=\xi$. (2). 若 $f$ 单调递增, 试证 ...
- fork/join使用示例
fork/join框架是用多线程的方式实现分治法来解决问题.fork指的是将问题不断地缩小规模,join是指根据子问题的计算结果,得出更高层次的结果. fork/join框架的使用有一定的约束条件: ...
- 利用Javascript获取当前日期的农历日期
来源:http://www.ido321.com/926.html JavaScript代码 1: /*设置农历日期*/ 2: var CalendarData=new Array(100); 3: ...
- Nuttx操作系统
前几天答辩的时候看到有同学在用,回来后查了点资料. 来源:天又亮了 1 NuttX 实时操作系统 NuttX 是一个实时操作系统(RTOS),强调标准兼容和小型封装,具有从8位到32位微控制器环境的 ...
- 时间,闰秒,及NTP
1.时间 格林尼治时间 GMT,以地球自转为准的时间,也叫世界时UT,但是由于自转速度会变化,所以后来不被作为标准. 世界协调时UTC,以原子钟为准,现在时间校准的标准就是原子钟. 2.闰秒 是指地球 ...
- 基础排序算法,java实现(快速,冒泡,选择,堆排序,插入)
1.冒泡排序: (1)比较相邻的元素.如果第一个比第二个大,就交换他们两个. (2)外面再套个循环就行. 算法复杂度:O(N2) 不罗嗦,上代码: //冒泡排序(两两交换,外加一个外循环) pub ...
- homework-02 "最大子数组之和"的问题进阶
代码编写 这次的作业瞬间难了好多,无论是问题本身的难度或者是单元测试这一原来没接触过的概念或者是命令行参数的处理这些琐碎的问题,都使得这次作业的完成说不上轻松. 最大子数组之和垂直水平相连的拓展问题解 ...
- Caroline--chochukmo
Caroline--chochukmo 虾米试听 Caroline, Caroline, Caroline, you pulled me into so deep down(内心深处). Caroli ...
- codeforces 617BChocolate
B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...