HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)
50 years, 50 colors
To celebrate this meaningful day, the ACM team of HDU hold some fuuny games. Especially, there will be a game named "crashing color balloons".
There will be a n*n matrix board on the ground, and each grid will have a color balloon in it.And the color of the ballon will be in the range of [1, 50].After the referee shouts "go!",you can begin to crash the balloons.Every time you can only choose one kind
of balloon to crash, we define that the two balloons with the same color belong to the same kind.What's more, each time you can only choose a single row or column of balloon, and crash the balloons that with the color you had chosen. Of course, a lot of students
are waiting to play this game, so we just give every student k times to crash the balloons.
Here comes the problem: which kind of balloon is impossible to be all crashed by a student in k times.
color of the ballon in the i row, j column.Input ends with n = k = 0.
1 1
1
2 1
1 1
1 2
2 1
1 2
2 2
5 4
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
3 3
50 50 50
50 50 50
50 50 50
0 0
-1
1
2
1 2 3 4 5
-1
有这样一个矩阵,矩阵里面是气球。气球有颜色编号1-50,询问在k次之内能不能把同种颜色存在的气球消掉(每次询问有K次机会),超过K此的气球编号,储存起来,并按编号按升序输出。
题意不是非常好理解,可是看明确之后,就非常清晰了
求最小点覆盖——即 用最少的点覆盖图中最多的边。
依次枚举就能够
矩阵的一维下标 当做 X集合,二维下标当做Y集合,询问全部点的最大匹配,比K大自然不满足
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#define init(a) memset(a,0,sizeof(a))
#define PI acos(-1,0)
using namespace std;
const int maxn = 110;
const int maxm = 100001;
#define lson left, m, id<<1
#define rson m+1, right, id<<1|1
#define min(a,b) (a>b)?b:a
#define max(a,b) (a>b)?a:b
const int N = 50010;
int ma[maxn][maxn];
int line[maxn],res[maxn];
bool vis[maxn],bj[maxn];
int k,n,m,t;
int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
int DFS(int st,int u)
{
for(int v = 1;v<=n;v++)
{
if(ma[u][v]== st && !vis[v])
{
vis[v] = 1;
if(line[v]==-1 || DFS(st,line[v]))
{
line[v] = u;
return 1;
}
}
}
return 0;
}
int K_M(int st)
{
memset(line,-1,sizeof(line));
int ans = 0;
for(int i = 1;i<=n;i++)
{
init(vis);
ans += DFS(st,i);
}
return ans;
}
int main()
{
int t;
while(~scanf("%d%d",&n,&k))
{
if(n==0 && k== 0) break;
init(ma); init(res); init(bj);
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=n;j++)
{
scanf("%d",&t);
ma[i][j] = t;
if(!bj[t])
bj[t] = 1;
}
}
int cnt,num = 0;
for(int i = 1;i<=55;i++)
{
if(bj[i])
{
cnt = K_M(i);
(cnt>k)?(res[num++] = i):(1);
}
}
if(num==0) puts("-1");
else
{
//sort(res,res+num);
qsort(res,num,sizeof(res[0]),cmp);
for(int j = 0;j<num-1;j++)
printf("%d ",res[j]);
printf("%d\n",res[num-1]);
}
}
return 0;
}
HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)的更多相关文章
- hdu 1498 50 years, 50 colors 最小点覆盖
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu1498 50 years, 50 colors --- 最小点覆盖
给一个矩阵,里面有一些不同颜色的气球.每次能够消灭一行或一列中某一种颜色的气球,问你在k次及以内,有哪些颜色的气球是不管怎样也消不完的. 那么思路就是,对每一种颜色的气球求最小点覆盖.>k 则为 ...
- HDU - 1054 Strategic Game(二分图最小点覆盖/树形dp)
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用ST ...
- hdu - 1150 Machine Schedule (二分图匹配最小点覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两种机器,A机器有n种模式,B机器有m种模式,现在有k个任务需要执行,没切换一个任务机器就需要重启一次, ...
- 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 ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- PHP判断远程文件是否存在的几种方法
在做一个图片预览中图的东西,遇到一个问题,就是要判断远程文件是否存在(不是同一台服务器). 代码如下: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 ...
- ctfmon.exe开机无法自己主动启动
打开命令提示符(開始菜单--执行--输入:cmd),输入下面命令(复制粘贴就可以): reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Ru ...
- SharePoint2010 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV4
在SharePoint2010开发中,选择部署类型为“部署为沙盒解决方案”,在部署代码是出现如下错误提示: 部署步骤“激活功能”中出现错误:无法启动计算机“PCName”上的服务SPUserCodeV ...
- Joomla3.1.1在64位win7下安装
将下载的joomla压缩包解压到Apache下的htdocs文件夹中. 打开Apache服务器,在浏览器输入http://localhost:8081/Joomla/ 即可进入Joolma的安装配置界 ...
- Android ListView 之 SimpleAdapter 二 (包含 item 中按钮监听)
1 MainActivity.java package com.myadapter; import java.util.ArrayList; import java.util.HashMap; ...
- Head First PHP &MySQL学习笔记
近期一段时间在学习PHP,买了<Head First PHP&MySQL>中文版这本书,之前买过<Head First设计模式>,感觉这系列的书籍整体来说非常不错. ...
- SuperSocket应用之FTP源码解析
一 简述 命令行协议是一种使用比较多的协议,其优点在于使用简单易于扩展性,同时也利于解析和使用.FTP,POP,SMTP等均采用命令行协议,其中FTP在早起互联网时期成为网络资源共享的主要方式,可见F ...
- linux脚本初体验
前言 第一次写linux脚本,有点紧张. 1. 写一个寻找特定用户的脚本文件? #! /bin/sh who | grep $1 其中脚本第一行用来告诉kernel去使用/bin/sh来解释这个脚本: ...
- VIM 用正则表达式
VIM 用正则表达式 批量替换文本,多行删除,复制,移动 在VIM中 用正则表达式 批量替换文本,多行删除,复制,移动 :n1,n2 m n3 移动n1-n2行(包括n1,n2)到n3行之下: ...
- 怎样取消shutdown关机命令?-shutdown命令的使用解析
机房上课,可恶电脑总是被管理员測试,不时地弹出这个关机提示.怎样取消这个关机命令呢?其有用 shutdown -a 就可以.以下来学习一下shutdown命令的使用: shutdown这个命令预计 ...