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冲杯之路 ] P1116
不充钱,你怎么AC? 题目:http://codevs.cn/problem/1116/ 数据很小,DFS可A,每层枚举颜色,判断相邻的点是否有重复的颜色,记得回溯时把颜色染回0,即无颜色 这里我使用 ...
- YYH的积木(NOIP模拟赛Round 6)
题目描述 YYH手上有n盒积木,每个积木有个重量.现在他想从每盒积木中拿一块积木,放在一起,这一堆积木的重量为每块积木的重量和.现在他想知道重量最少的k种取法的重量分别是多少. 输入输出格式 输入格式 ...
- pip3 快速安装
https://www.cnblogs.com/wenchengxiaopenyou/p/5709218.html
- zmap zgrab 环境搭建
yum install cmake gmp-devel gengetopt libpcap-devel flex byacc json-c-devel libunistring-devel golan ...
- flask框架基本使用(2)(响应与重定向)
#转载请留言联系 flask 框架基本使用(1):https://www.cnblogs.com/chichung/p/9756935.html 1. flask 自定义返回状态码与响应头 from ...
- 在线查看PDF文档
http://www.cnblogs.com/morang/p/4598894.html http://78re52.com1.z0.glb.clouddn.com/resource%2Fscenar ...
- [BZOJ1052][HAOI2007]覆盖问题 二分+贪心
1052: [HAOI2007]覆盖问题 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2053 Solved: 959 [Submit][Sta ...
- HDU 2586.How far away ?-在线LCA(ST)-代码很认真的写了注释(捞到变形)
2018.9.10 0:40 重新敲一遍,然后很认真的写了注释,方便自己和队友看,刚过去的一天的下午打网络赛有一题用到了这个,但是没写注释,队友改板子有点伤,因为我没注释... 以后写博客,代码要写注 ...
- Codeforces 935E Fafa and Ancient Mathematics(表达式转树 + 树型DP)
题目链接 Codeforces Round #465 (Div. 2) Problem E 题意 给定一个表达式,然后用$P$个加号和$M$个减号填充所有的问号(保证问号个数等于$P + M$) ...
- C语言基础之函数
1.什么情况下定义函数: 添加一个常用的新功能 2.函数的定义格式 返回值类型 函数名(形式参数列表) { 函数体 } 3.定义函数需要明确的东西 1> 起一个有意义的函数名 2> 函数 ...