Hdu 1498 二分匹配
50 years, 50 colors
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1484 Accepted Submission(s): 798Problem DescriptionOn 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.
InputThere 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.OutputFor 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 Input1 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 0Sample Output-1
1
2
1 2 3 4 5
-1
/*************************************************************************
> File Name: 1498.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月14日 星期一 22时35分33秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int MAX_N = + ;
int n, k;
int cx[MAX_N], cy[MAX_N], mark[MAX_N];
int G[MAX_N][MAX_N], A[MAX_N][MAX_N], ans[MAX_N]; int
path(int u) {
for (int v = ; v <= n; v++) {
if (!mark[v] && G[u][v]) {
mark[v] = ;
if (cy[v] == - || path(cy[v])) {
cx[u] = v;
cy[v] = u;
return ;
}
}
}
return ;
} int
MaxMatch() {
memset(cx, -, sizeof(cx));
memset(cy, -, sizeof(cy));
int res = ;
for (int i = ; i <= n; i++) {
if (cx[i] == -) {
memset(mark, , sizeof(mark));
res += path(i);
}
}
return res;
} void
init(int x) {
memset(G, , sizeof(G));
for (int i = ; i <= n; i++) for (int j = ; j <= n; j++) if (A[i][j] == x) {
G[i][j] = ;
}
} void
solve() {
int cnt = ;
for (int i = ; i <= ; i++) {
init(i);
if (MaxMatch() > k) ans[cnt++] = i;
}
if (cnt == ) {
puts("-1");
}
else {
for (int i = ; i < cnt; i++) {
printf("%d%c", ans[i], i == cnt- ? '\n' : ' ');
}
}
} int
main(void) {
while (~scanf("%d %d", &n, &k) && n+k) {
for (int i = ; i <= n; i++) {
for (int j = ; j <= n; j++) {
scanf("%d", &A[i][j]);
}
}
solve();
} return ;
}
Hdu 1498 二分匹配的更多相关文章
- hdu 4169 二分匹配最大独立集 ***
题意:有水平N张牌,竖直M张牌,同一方向的牌不会相交.水平的和垂直的可能会相交,求最少踢出去几张牌使剩下的牌都不相交. 二分匹配 最小点覆盖=最大匹配. 链接:点我 坐标点作为匹配的端点 #inclu ...
- hdu 5093 二分匹配
/* 题意:给你一些冰岛.公共海域和浮冰,冰岛可以隔开两个公共海域,浮冰无影响 求选尽可能多的选一些公共海域点每行每列仅能选一个. 限制条件:冰山可以隔开这个限制条件.即*#*可以选两个 预处理: * ...
- Battle ships HDU - 5093二分匹配
Battle shipsHDU - 5093 题目大意:n*m的地图,*代表海洋,#代表冰山,o代表浮冰,海洋上可以放置船舰,但是每一行每一列只能有一个船舰(类似象棋的車),除非同行或者同列的船舰中间 ...
- hdu 4685 二分匹配+强连通分量
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4685 题解: 这一题是poj 1904的加强版,poj 1904王子和公主的人数是一样多的,并且给出 ...
- POJ 1498[二分匹配——最小顶点覆盖]
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=1498] 题意:给出一个大小为n*n(0<n<100)的矩阵,矩阵中放入m种颜色(标号为1 ...
- H - Prince and Princess - HDU 4685(二分匹配+强连通分量)
题意:有N个王子M个公主,王子喜欢一些公主,而且只能是王子喜欢的人,他们才可以结婚,现在让他们尽可能多的结婚的前提下找出来每个王子都可以和谁结婚. 分析:先求出来他们的最大匹配,因为给的数据未必是完备 ...
- HDU 3729 二分匹配 反向匹配
题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定 点 ...
- HDU -1151 二分匹配与有向无环图不相交最小路径覆盖数
题意: 考虑一个小镇,那里的所有街道都是单向的,并且每条街道都从一个路口通往另一个路口.还众所周知,从一个十字路口开始,穿过城镇的街道,您将永远无法到达同一十字路口,即,城镇的街道没有环. 基于这些假 ...
- HDU 2603 二分匹配
#include <queue>#include <vector>#include <cstdio>#include <cstring>#include ...
- hdu 1528 二分匹配
#include<stdio.h> #include<string.h> int map[100][100],mark[100],link[100],max2,k; int f ...
随机推荐
- linux服务器之间传输文件
转载:https://www.jb51.net/article/82608.htm 1. scp(最近就使用了scp) [优点]简单方便,安全可靠:支持限速参数 [缺点]不支持排除目录[用法]scp就 ...
- nginx配置虚拟主机的两种方式
一. 通过端口区分不同的虚拟主机 二. 通过域名区分不同的虚拟主机 备注: 1)hosts文件路径:
- HZOI2019 砍树 整除分块
题目链接:https://www.cnblogs.com/Juve/articles/11207540.html(密码你懂的)——————————>> 这题... 一开始想的二分,但此题不 ...
- Android实战技巧之四十一:制作自己的Android SDK
标签: sdkandroid定制sdk 2015-09-21 18:05 11237人阅读 评论(2) 收藏 举报 分类: Android(260) 版权声明:本文为博主原创文章,未经博主允许 ...
- SQLServer-SQLServer2017:安装 SQL Server 的硬件和软件要求
ylbtech-SQLServer-SQLServer2017:安装 SQL Server 的硬件和软件要求 1.返回顶部 1. 安装 SQL Server 的硬件和软件要求 2018/11/06 适 ...
- MyBatis配置文件(四)--typeHandlers
typeHandlers又叫类型处理器,就像在JDBC中,我们在PreparedStatement中设置预编译sql所需的参数或执行sql后根据结果集ResultSet对象获取得到的数据时,需要将数据 ...
- tensorflow 利用python generate_cifar10_tfrecords.py --data-dir=${PWD}/cifar-10-data报错
报的错误如下:UnicodeDecodeError: 'ascii' codec can't decode byte 0x9e in position 0: ordinal not in range( ...
- 2019-8-31-C#-程序集数量对软件启动性能的影响
title author date CreateTime categories C# 程序集数量对软件启动性能的影响 lindexi 2019-08-31 16:55:58 +0800 2018-10 ...
- npm config set registry 与 cnpm的区别
一直以为这2个事没有区别的: npm config set registry http://registry.npm.taobao.org 后使用npm命令. npm install -g cnpm ...
- 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践
1. 概述 数据服务(https://ds-cn-shanghai.data.aliyun.com) 是DataWorks产品家族的一员,提供了快速将数据表生成API的能力,通过可视化的向导,一分钟“ ...
