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 ...
随机推荐
- hdu 6119 …&&百度之星 T6
小小粉丝度度熊 Problem Description 度度熊喜欢着喵哈哈村的大明星——星星小姐. 为什么度度熊会喜欢星星小姐呢? 首先星星小姐笑起来非常动人,其次星星小姐唱歌也非常好听. 但这都不是 ...
- zepto.js 自定义打包集成其他模块构建流程
1.首先在自己的电脑上要安装Node.js和npm包管理工具: 2.从github上下载zepto.js的源文件包到本地磁盘(例如:E:\Learning\JS): 地址:https://github ...
- rootkit 内核函数hook
转自:https://0x90syntax.wordpress.com/2016/02/21/suterusu-rootkitx86%e4%b8%8earm%e7%9a%84%e5%86%85%e8% ...
- ReferenceError与undefined的区别
ReferenceError与undefined的区别 概述 ReferenceError 当尝试引用一个未定义的变量/函数时,就会抛出一个ReferenceError. undefined 当一个变 ...
- OpenGL函数思考-glColor
http://blog.csdn.net/shuaihj/article/details/7231980 OpenGL函数思考-glColor 函数原型: glColor3b,glColor ...
- 查看gcc/g++默认include路径
转自:http://gcc.gnu.org/ml/gcc-help/2007-09/msg00205.html `gcc -print-prog-name=cc1plus` -v `g++ -prin ...
- python的优化机制与垃圾回收与gc模块
python属于动态语言,我们可以随意的创建和销毁变量,如果频繁的创建和销毁则会浪费cpu,那么python内部是如何优化的呢? python和其他很多高级语言一样,都自带垃圾回收机制,不用我们去维护 ...
- Appium+python自动化2-环境搭建(下)【转载】
前言 上一篇android测试开发环境已经准备好, 接下来就是appium的环境安装了.环境安装过程中切勿浮躁,按照步骤一个个来. 环境装好后,可以用真机连电脑,也可以用android-sdk里 ...
- 来杯咖啡-装饰者模式(Decorator)
前言 上篇[观察者模式]发布已经近一个月了,个人感觉反应并不太理想,因为大家响应都不是很积极,不知是文章那里写得有问题,而且也没有人提出过有价值的改进建议,多少感觉有些失望L!因为工作繁忙,所以不可能 ...
- AC日记——Broken BST codeforces 797d
D - Broken BST 思路: 二叉搜索树: 它时间很优是因为每次都能把区间缩减为原来的一半: 所以,我们每次都缩减权值区间. 然后判断dis[now]是否在区间中: 代码: #include ...