poj 1719Shooting Contest
//本题大意是对于一个r*c的矩阵,每一列有两个是白色的
//如今选c个位置,要求每一行至少有一个白色的方格被选上
//每一列仅仅能选一个
//用二分匹配求出最大匹配,假设最大匹配等于r,则满足
//每一行至少有一个白色的格子被选上
//注意c>r的情况
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1010;
int line[maxn][maxn];
int match[maxn];
int match_ans[maxn];
int vis[maxn];
int r,c;
int find(int start)
{
int i ;
for(i=1;i<=r;i++)
{
if(line[start][i]&&!vis[i])
{
vis[i]=1;
if(match[i]==-1||find(match[i]))
{
match[i] = start ;
match_ans[start] = i;
return 1;
}
}
}
return 0;
}
void Match()
{
int i;
memset(match , -1 ,sizeof(match));
int ans = 0;
for(i = 1; i <= c;i++)
{
memset(vis , 0 , sizeof(vis));
if(find(i))
ans++;
}
if(ans == r)
{
for(i = 1;i <= c; i++)
{
if(!match_ans[i])
{
for(int j = 1;j <= r ;j++)
if(line[i][j])
{
printf("%d%c",j,i == c?'\n':' ');
break;
}
}
else
printf("%d%c",match_ans[i],i == c?
'\n':' ');
}
}
else
printf("NO\n");
}
int main()
{
//freopen("in.txt", "r" ,stdin);
int T;
scanf("%d", &T);
while(T--)
{
memset(line, 0 ,sizeof(line));
memset(match_ans , 0 ,sizeof(match_ans));
scanf("%d%d" ,&r , &c);
int a,b;
for(int i = 1; i <= c ;i++)
{
scanf("%d%d",&a ,&b);
line[i][a] = line[i][b] = 1;
}
Match();
}
return 1;
}
poj 1719Shooting Contest的更多相关文章
- poj 3660Cow Contest
题目链接:http://poj.org/problem?id=3660 有n头奶牛还有m种关系a,b表示a牛逼b彩笔,所以a排名比b高 最后问你给出的关系最多能确定多少头奶牛的排名,而且给出的数据不会 ...
- POJ 3204 Ikki's Story I - Road Reconstruction
Ikki's Story I - Road Reconstruction Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 7 ...
- POJ 3744 Scout YYF I
分段的概率DP+矩阵快速幂 Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- [最近公共祖先] POJ 3728 The merchant
The merchant Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 4556 Accepted: 1576 Desc ...
- POJ 3278 The merchant
传送门 Time Limit: 3000MS Memory Limit: 65536K Description There are N cities in a country, and there i ...
- Scout YYF I(POJ 3744)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5565 Accepted: 1553 Descr ...
- poj 3744 Scout YYF I (矩阵)
Description YYF -p. Here is the task, given the place of each mine, please calculate the probality t ...
- [POJ 3734] Blocks (矩阵高速幂、组合数学)
Blocks Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3997 Accepted: 1775 Descriptio ...
- poj 3728 The merchant(LCA)
Description There are N cities in a country, and there is one and only one simple path between each ...
随机推荐
- Codevs 2080 特殊的质数肋骨
题目描述 Description 农民约翰的母牛总是产生最好的肋骨. 你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的质数肋骨,是因为从右边开始切下肋 ...
- POJ3522 Slim Span
Slim Span Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7462 Accepted: 3959 Descrip ...
- poj 3744 Scout YYF 1 (概率DP+矩阵快速幂)
F - Scout YYF I Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- UVA 11125 Arrange Some Marbles
dp[i][j][m][n][s]表示最初选择j个i号颜色大理石.当前选择n个m号颜色大理石.剩余大理石状态(8进制数状压表示)最开始没看出状压..sad #include <map> # ...
- c# GDI画图 双缓冲画图分析
双缓冲绘图分析 1.Windows 绘图原理 我们在 Windows 环境下看到各种元素,如菜单.按钮.窗口.图像,从根本上说,都是“画”出来的.这时的屏幕,就相当于一块黑板,而 Windows ...
- wsgi的学习(2):uWSGI的概念
uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI / uwsgi / u ...
- 使用Laravel将数据Excel导出的方法
1.copmposer下载maatwebsite/excel 2.在控制器引入:use Excel; 3.将要导出的数据处理成数组,第一组数据为表的字段名,如图 4.导出成表格 Excel::crea ...
- nginx安全日志分析脚本的编写
https://blog.csdn.net/nextdoor6/article/details/51914966
- Python的程序结构[2] -> 类/Class[3] -> 内建类与内建函数
内建类与内建函数的区分 / Distinction of Built-in Type and Function 对于 Python,有许多可以不需要定义或引用就可以使用的函数(类)(参考内建模块),诸 ...
- 洛谷——P3395 路障
P3395 路障 题目背景 此题约为NOIP提高组Day1T1难度. 题目描述 B君站在一个n*n的棋盘上.最开始,B君站在(1,1)这个点,他要走到(n,n)这个点. B君每秒可以向上下左右的某个方 ...