题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498

50 years, 50 colors

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

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
 
Author
8600
 
Source
 
 
题目大意:刷气球,气球有很多种颜色。 每次刷气球可以刷一整行或者一整列,刷m次,最后输出刷不完的气球数字。(每个不同的数字代表不同颜色的气球)。
特别注意:气球的颜色数字范围在1~50之间。
 
详见代码(代码解释)
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,m;
int vis[],Map[][],ok[],cc[]; bool Find(int x,int now)
{
for (int i=; i<=n; i++)
{
if (!vis[i]&&Map[x][i]==now)
{
vis[i]=;
if (!ok[i])
{
ok[i]=x;
return true;
}
else
{
if (Find(ok[i],now))
{
ok[i]=x;
return true;
}
}
}
}
return false;
} int main()
{
int flag,ans,s[];
while (~scanf("%d%d",&n,&m))
{
flag=;
memset(cc,,sizeof(cc));
memset(Map,,sizeof(Map));
if (n==&&m==)
break;
for (int i=; i<=n; i++)
{
for (int j=; j<=n; j++)
{
scanf("%d",&Map[i][j]);
cc[Map[i][j]]=;//记录这个颜色出现过
}
}
memset(ok,,sizeof(ok));
int k=;
for (int i=; i<=; i++)
{
memset(ok,,sizeof(ok));
ans=;
if (cc[i]==) //判断颜色是否出现过,加入这里不进行标记的话最后输出的是没有被刷完的颜色数字,就会输出一些乱七八糟的东西
{
for (int j=; j<=n; j++)
{
memset(vis,,sizeof(vis));
if (Find(j,i))
ans++;
}
if (ans>m) //如果最大匹配数大于m次的话就是刷不完的
{
s[++k]=i;
flag=;
}
}
}
if (flag==)
printf ("-1\n");
else
{
for (int i=; i<k; i++) //控制输出格式
{
printf ("%d ",s[i]);
}
printf ("%d\n",s[k]);
}
}
return ;
}

hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)的更多相关文章

  1. hdu 3729 I'm Telling the Truth(二分匹配_ 匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth Time Limit: 2000/1000 MS ( ...

  2. HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdu2063 最大二分匹配(匈牙利算法)

    过山车 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. hdu 2063 过山车 二分匹配(匈牙利算法)

    简单题hdu2063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Ot ...

  5. POJ 3014:Asteroids(二分匹配,匈牙利算法)

    id=3041">Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14399   Acce ...

  6. 二分图的最大匹配以及带权匹配【匈牙利算法+KM算法】

    二分图算法包括 匈牙利算法 与 KM算法. 匈牙利算法 在这里写上模板. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 #include< ...

  7. HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)

    题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...

  8. HDU 6178 Monkeys(树上的二分匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:现在有一n个顶点的树形图,还有k只猴子,每个顶点只能容纳一只猴子,而且每只猴子至少和另外一只猴子通过 ...

  9. HDU - 3081 Marriage Match II 【二分匹配】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...

随机推荐

  1. Linux输入子系统:多点触控协议 -- multi-touch-protocol.txt768

    转自:http://blog.csdn.net/droidphone/article/details/8434768 Multi-touch (MT) Protocol --------------- ...

  2. 大型Java web项目分布式架构演进-分布式部署

    http://blog.csdn.net/binyao02123202/article/details/32340283/ 知乎相关文章https://www.zhihu.com/question/2 ...

  3. rxjs5.X系列 —— ErrorHandling/Condition/Mathematical系列 api 笔记

    欢迎指导与讨论 : ) 前言 本文是笔者翻译 RxJS 5.X 官网各类operation操作系列的的第四篇 —— ErrorHanding异常处理.Condition Operator情况操作.Ma ...

  4. PC和FPGA间的串口通信实现

    应用笔记 V1.0 2015/03/26 PC和FPGA间的串口通信实现   概述   本文将介绍PC和FPGA间的串口通信实现的基本思路和Verilog代码,对于通信而言,收发双方都要有相应的控制. ...

  5. 洛谷P3601签到题(欧拉函数)

    题目背景 这是一道签到题! 建议做题之前仔细阅读数据范围! 题目描述 我们定义一个函数:qiandao(x)为小于等于x的数中与x不互质的数的个数. 这题作为签到题,给出l和r,要求求. 输入输出格式 ...

  6. 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为1000。

    给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为1000. 示例 1: 输入: "babad" 输出: "bab" 注意: &quo ...

  7. 详解SQL Server数据修复命令DBCC的使用

    严重级别为 21 表示可能存在数据损坏. 可能的原因包括损坏的页链.损坏的 IAM 或该对象的 sys.objects目录视图中存在无效条目. 这些错误通常由硬件或磁盘设备驱动程序故障而引起. MS ...

  8. Golang基础(一)

    1. 变量声明与赋值 // var.go package main import "fmt" var a string var b bool var c string = &quo ...

  9. Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)

    原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...

  10. HSTS的来龙去脉

    前言 安全经常说“云.管.端”,“管”指的是管道,传输过程中的安全.为了确保信息在网络传输层的安全,现在很多网站都开启了HTTPS,也就是HTTP+TLS,在传输过程中对信息进行加密.HTTPS使用了 ...