poj 1719 Shooting Contest (二分匹配)
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 3812 | Accepted: 1389 | Special Judge | ||
Description
A volley of c shots is correct if exactly one white square is hit in each column and there is no row without white square being hit. Help the shooter to find a correct volley of hits if such a volley exists.
Example
Consider the following target: 
Volley of hits at white squares in rows 2, 3, 1, 4 in consecutive columns 1, 2, 3, 4 is correct.
Write a program that: verifies whether any correct volley of hits exists and if so, finds one of them.
Input
The first line of each block contains two integers r and c separated by a single space, 2 <= r <= c <= 1000. These are the numbers of rows and columns, respectively. Each of the next c lines in the block contains two integers separated by a single space. The integers in the input line i + 1 in the block, 1 <= i <= c, are labels of rows with white squares in the i-th column.
Output
Sample Input
2
4 4
2 4
3 4
1 3
1 4
5 5
1 5
2 4
3 4
2 4
2 3
Sample Output
2 3 1 4
NO
Source
//220K 110MS C++ 1341B 2014-06-03 15:44:38
//每列一个,每行至少一个
#include<iostream>
#include<vector>
#define N 1005
using namespace std;
vector<int>V[N];
int vis[N];
int match[N];
int p[N][];
int n,m;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
memset(match,-,sizeof(match));
int ret=;
for(int i=;i<=m;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++) V[i].clear();
for(int i=;i<=m;i++){
scanf("%d%d",&p[i][],&p[i][]);
V[i].push_back(p[i][]);
V[i].push_back(p[i][]);
}
int prt[N]={};
if(hungary()==n){
for(int i=;i<=n;i++)
prt[match[i]]=i;
for(int i=;i<m;i++)
if(prt[i]==) printf("%d ",p[i][]);
else printf("%d ",prt[i]);
if(prt[m]==) printf("%d\n",p[m][]);
else printf("%d\n",prt[m]);
}else puts("NO");
}
return ;
}
poj 1719 Shooting Contest (二分匹配)的更多相关文章
- POJ 1719 Shooting Contest(二分图匹配)
POJ 1719 Shooting Contest id=1719" target="_blank" style="">题目链接 题意:给定一个 ...
- poj 1719 Shooting Contest
http://poj.org/problem?id=1719 Shooting Contest Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- poj 3057(bfs+二分匹配)
题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区 ...
- POJ 1469(裸二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18993 Accepted: 7486 Descript ...
- poj 2584 T-Shirt Gumbo (二分匹配)
T-Shirt Gumbo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2571 Accepted: 1202 Des ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...
随机推荐
- 北京Uber优步司机奖励政策(4月8日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 北京Uber优步司机奖励政策(3月9日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 屏蔽Drupal中的“Notice: Undefined index”警告
原因:drupal默认使用E_ALL,即输出所有错误和警告.我们只需要修改错误显示级别即可. 方法: 1. 打开\sites\default\settings.php 追加一行 ini_set('er ...
- 拼接index
import MySQLdb import sys db = MySQLdb.connect(host="127.0.0.1", # your host, usually loca ...
- 2019年猪年海报PSD模板-第四部分
14套精美猪年海报,免费猪年海报,下载地址:百度网盘,https://pan.baidu.com/s/1WUO4L5PHIHG5hAurv52_2A
- Spring Boot下的lombok安装 (日志) 不能识别log变量问题
参考地址:http://blog.csdn.net/blueheart20/article/details/52909775 ps:除了要加载依赖之外 还要安装lombok插件
- git 跟踪分支 远程跟踪分支 学习笔记
远程跟踪分支相当于一个只读仓库指针,从服务器上获取数据,不可以被本地直接修改. 跟踪分支相当于一个本地指针 用于项目更新和迭代. 1跟踪分支 (tracking branch) 逻辑示意图 ...
- Dreamweaver CS5网页制作教程
说到Dreamweaver这个网页制作神器,不由得想起在学校里上的选修课,那是的我们只知道 table 布局,只知道构建网站最方便的是使用“所见即所得”编辑器.回忆一下,真的是很怀旧啊! 虽说咱现在大 ...
- LeetCode - 463. Island Perimeter - O(MN)- (C++) - 解题报告
原题 原题链接 You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 ...
- IntelliJ IDEA 2017.3/2018.1/.2 激活
传统的License Server方式已经无法注册IntelliJ IDEA2017.3的版本了. http://idea.lanyus.com,这个网站有破解补丁和注册码两种方式,另外http:// ...