50 years, 50 colors

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2256    Accepted Submission(s): 1266

Problem Description
On
Octorber 21st, HDU 50-year-celebration, 50-color balloons floating
around the campus, it's so nice, isn't it? 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.

 
Input
There
will be multiple input cases.Each test case begins with two integers n,
k. n is the number of rows and columns of the balloons (1 <= n <=
100), and k is the times that ginving to each student(0 < k <=
n).Follow a matrix A of n*n, where Aij denote the color of the ballon in
the i row, j column.Input ends with n = k = 0.
 
Output
For
each test case, print in ascending order all the colors of which are
impossible to be crashed by a student in k times. If there is no choice,
print "-1".
 
Sample Input
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
 
Sample Output
-1
1
2
1 2 3 4 5
-1
 

题意:给出一个矩阵,里面有一些颜色不同的气球,一次能够消灭一行或者一列的气球,问某一种颜色的气球能否在 k 次内消除完毕,如果不能则输出气球颜色编号,如果全部可以则输出-1.

题解:最小点覆盖问题,枚举每一种颜色的气球,然后对每一个做一次最大匹配,如果最大匹配>k,则不能够消灭.时间复杂度O(n^3) ,这都能在62MS跑过去,数据太水。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
int n,k;
int graph[N][N],graph1[N][N];
int linker[N],result[N];
bool vis[N];
int Hash[];
bool dfs(int u){
for(int v=;v<n;v++){
if(graph1[u][v]&&!vis[v]){
vis[v] = true;
if(linker[v]==-||dfs(linker[v])){
linker[v] = u;
return true;
}
}
}
return false;
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF){
if(n==&&k==) break;
memset(Hash,,sizeof(Hash));
for(int i=;i<n;i++){
for(int j=;j<n;j++){
scanf("%d",&graph[i][j]);
Hash[graph[i][j]] = ;
}
}
int m = ;
for(int i=;i<=;i++){
if(!Hash[i]) continue;
memset(graph1,,sizeof(graph1));
memset(linker,-,sizeof(linker));
for(int j=;j<n;j++){
for(int k=;k<n;k++){
if(graph[j][k]==i) {
graph1[j][k] = ;
}
}
}
int res = ;
for(int u=;u<n;u++){
memset(vis,,sizeof(vis));
if(dfs(u)) res++;
}
if(res>k) result[m++] = i;
}
if(m==){
printf("-1\n");
continue;
}
for(int i=;i<m-;i++){
printf("%d ",result[i]);
}
printf("%d\n",result[m-]);
}
return ;
}

hdu 1498(最小点覆盖集)的更多相关文章

  1. hdu 1054(最小点覆盖集)

    Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)

    //匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...

  3. POJ2226 Muddy Fields(二分图最小点覆盖集)

    题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...

  4. POJ1325 Machine Schedule(二分图最小点覆盖集)

    最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...

  5. Jewelry Exhibition(最小点覆盖集)

    Jewelry Exhibition 时间限制: 1 Sec  内存限制: 64 MB提交: 3  解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...

  6. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)

    题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...

  7. POJ 3041 Asteroids (最小点覆盖集)

    题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...

  8. 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...

  9. POJ 3041 Asteroids (二分图最小点覆盖集)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24789   Accepted: 13439 Descr ...

随机推荐

  1. User Agent的学习

    什么是User-Agent? User-Agent是一个特殊字符串头,被广泛用来标示浏览器客户端的信息,使得服务器能识别客户机使用的操作系统和版本,CPU类型,浏览器及版本,浏览器的渲染引擎,浏览器语 ...

  2. Mybatis学习系列(一)入门简介

    MyBatis简介 Mybatis是Apache的一个Java开源项目,是一个支持动态Sql语句的持久层框架.Mybatis可以将Sql语句配置在XML文件中,避免将Sql语句硬编码在Java类中.与 ...

  3. ArcGis下的叠加分析

     1矢量与矢量叠加的话就用ToolBox里有Overlay: 2如果是矢量和栅格叠加的话用Spatial analysis模块中的 zonal statistics: 3还有就是栅格与栅格的叠加S ...

  4. P3434 [POI2006]KRA-The Disks

    题目描述 For his birthday present little Johnny has received from his parents a new plaything which cons ...

  5. HDU 2639 01背包求第k大

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. centos6上使用fpm打python2.7 rpm包并兼容python2.6

    centos6上使用fpm打python2.7 rpm包并兼容python2.6 作者 运维小兵_加油 关注 2016.09.22 00:28 字数 501 阅读 45评论 0喜欢 1 工作中我们常常 ...

  7. PHP设计模式-工厂模式、单例模式、注册模式

    本文参考慕课网<大话PHP设计模式>-第五章内容编写,视频路径为:http://www.imooc.com/video/4876 推荐阅读我之前的文章:php的设计模式 三种基本设计模式, ...

  8. 转:RBAC权限控制

    名词解释: RBAC:Role-Based Access Control,基于角色的访问控制   关键词: RBAC,Java Shiro,Spring Security,   一. RBAC 要解决 ...

  9. 【BZOJ3942】Censoring [KMP]

    Censoring Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 有一个S串和一个T串,长 ...

  10. 【比赛】百度之星2017 初赛Round B

    第一题 题意:给定n*m网络,定义两个棋子在同行同列则相互攻击,同时要求两个棋子的行和列不能一小一大,求满足条件的最大摆放的方案数. 题解:ans=C(max(n,m),min(n,m)),就是在ma ...