hdu 1498(最小点覆盖集)
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
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.
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.
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".
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
2
1 2 3 4 5
-1
题意:给出一个矩阵,里面有一些颜色不同的气球,一次能够消灭一行或者一列的气球,问某一种颜色的气球能否在 k 次内消除完毕,如果不能则输出气球颜色编号,如果全部可以则输出-1.
#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(最小点覆盖集)的更多相关文章
- hdu 1054(最小点覆盖集)
Strategic Game Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- ACM/ICPC 之 机器调度-匈牙利算法解最小点覆盖集(DFS)(POJ1325)
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring&g ...
- POJ2226 Muddy Fields(二分图最小点覆盖集)
题目给张R×C的地图,地图上*表示泥地..表示草地,问最少要几块宽1长任意木板才能盖住所有泥地,木板可以重合但不能盖住草地. 把所有行和列连续的泥地(可以放一块木板铺满的)看作点且行和列连续泥地分别作 ...
- POJ1325 Machine Schedule(二分图最小点覆盖集)
最小点覆盖集就是在一个有向图中选出最少的点集,使其覆盖所有的边. 二分图最小点覆盖集=二分图最大匹配(二分图最大边独立集) 这题A机器的n种模式作为X部的点,B机器的m种模式作为Y部的点: 每个任务就 ...
- Jewelry Exhibition(最小点覆盖集)
Jewelry Exhibition 时间限制: 1 Sec 内存限制: 64 MB提交: 3 解决: 3[提交][状态][讨论版] 题目描述 To guard the art jewelry e ...
- POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
题意 给出的是N*M的矩阵,同样是有障碍的格子,要求每次只能消除一行或一列中连续的格子,最少消除多少次可以全部清除. 思路 相当于POJ 3041升级版,不同之处在于这次不能一列一行全部消掉,那些非障 ...
- POJ 3041 Asteroids (最小点覆盖集)
题意 给出一个N*N的矩阵,有些格子上有障碍,要求每次消除一行或者一列的障碍,最少消除多少次可以全部清除障碍. 思路 把关键点取出来:一个障碍至少需要被它的行或者列中的一个消除. 也许是最近在做二分图 ...
- 二分图变种之最小路径覆盖、最小点覆盖集【poj3041】【poj2060】
[pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=54859604 向大(hei)佬(e)势力学(di ...
- POJ 3041 Asteroids (二分图最小点覆盖集)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24789 Accepted: 13439 Descr ...
随机推荐
- 猜数字(C语言版)
编程先由计算机“想”一个1到100之间的数请人猜,如果人猜对了,则结束游戏,并在屏幕上输出人猜了多少次才猜对此数,以此来反映猜数者“猜”的水平,否则计算机给出提示,告诉人所猜的数是太大还是太小,最多可 ...
- [HAOI2007]理想的正方形 st表 || 单调队列
~~~题面~~~ 题解: 因为数据范围不大,而且题目要求的是正方形,所以这道题有2种解法. 1,st表. 这种解法暴力好写好理解,但是较慢.我们设st[i][j][k]表示以(i, j)为左端点,向下 ...
- redux的基本概念
1. State 应用的数据,即状态 2. Action 一个纯对象,携带这个操作的类型和数据信息,主要是用来进行传递信息,如下所示: const action = { type: 'ADD_TODO ...
- 解决Vue方法中setTimeout改变变量的值无效
把data里的变量继承过来重新封装一下 let that = this; this.rightAnswer = false; setTimeout(function() { that.rightAns ...
- innodb_stats_on_metadata and slow queries on INFORMATION_SCHEMA
INFORMATION_SCHEMA is usually the place to go when you want to get facts about a system (how many ta ...
- HDU4280:Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- Array.slice(start,end)的用法
start在start>=0,假设start=0,表示从数组的第一个元素开始截取,start=2,表示从数组的第二个元素开始截取,依次类推. 在start<0时,start=-1表示从倒数 ...
- bzoj 2566 calc 拉格朗日插值
calc Time Limit: 30 Sec Memory Limit: 512 MBSubmit: 377 Solved: 226[Submit][Status][Discuss] Descr ...
- [洛谷P2420] 让我们异或吧
题目链接:让我们异或吧 题目描述 异或是一种神奇的运算,大部分人把它总结成不进位加法. 在生活中…xor运算也很常见.比如,对于一个问题的回答,是为1,否为0.那么: (A是否是男生 )xor( B是 ...
- jsp和servlet之间传数据
一.jsp与java文件传递数据可以使用Servlet类来传递,jsp将数据存入到request对象中,Servlet类获取这个request对象,并将数据取出. 示例代码如下: JSP代码: < ...