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. springMVC js等文件找不到解决方法

    <mvc:resources mapping="/javascript/**" location="/static_resources/javascript/&qu ...

  2. wait_event_interruptible_timeout

    最近一套方案涉及到内核线程之间的同步,用到了函数wait_event_interruptible_timeout函数,大致是这样: A:是一个后台的线程,平常没事就睡觉,有时被唤醒,或者每5分钟醒一次 ...

  3. hibernate多表查询

    一对多进行查询(用懒加载的模式) 查找区域所对应的街道: Dao: public Qu selQu(String dno){ Session session=HibernateSessionFacto ...

  4. C# + ArcEngine 常用方法(不定时更新)

    1.Arcengine调用GP服务,抛出异常方法 object sev = null; try { Application.DoEvents(); gp.Execute(gpBuildPyramids ...

  5. string 类型转换

    string转int "; int n = atoi(str.c_str()); cout << n << endl; int转string #include < ...

  6. echarts中图表过于靠左或靠右的情况解决办法。

    经过好多次尝试,终于在http://blog.csdn.net/ainuser/article/details/76641963中得到解决. grid: { x: '30%', //相当于距离左边效果 ...

  7. [ZJOI2005]午餐 (DP)

    [ZJOI2005]午餐 题目描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的口味(以及胃口 ...

  8. [hdu 3068] Manacher算法O(n)最长回文子串

    一个不错的讲解:https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/01.05.md # ...

  9. HDU 多校对抗 F Naive Operations

    Naive Operations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 502768/502768 K (Java/Other ...

  10. mysql 基本操作练习

    ), sex ), age )); , '北京'); , '上海'); , '广州'); , '北京'); , '北京'); , '上海'); , '北京'); #(). 写出sql语句,查询所有年龄 ...