hdu 1281 棋盘游戏 (二分匹配)
//是象棋里的车 符合二分匹配
# include<stdio.h>
# include<algorithm>
# include<string.h>
using namespace std;
int n,m,pp[110][110],map[110],vis[110];
int bfs(int x)
{
for(int i=1;i<=m;i++)
{
if(!vis[i]&&pp[x][i])
{
vis[i]=1;
if(!map[i]||bfs(map[i]))
{
map[i]=x;
return 1;
}
}
}
return 0;
}
int f()
{
int a=0;
memset(map,0,sizeof(map));
for(int i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(bfs(i))
a++;
}
return a;
}
int main()
{
int i,j,k,cot1=0,ans,a,b;
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(pp,0,sizeof(pp));
for(i=0;i<k;i++)
{
scanf("%d%d",&a,&b);
pp[a][b]=1;
}
int cot=f();
ans=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(pp[i][j])//推断是否为重要点
{
pp[i][j]=0;
if(f()<cot)
ans++;
pp[i][j]=1; }
}
}
printf("Board %d have %d important blanks for %d chessmen.\n",++cot1,ans,cot);
}
return 0;
}
hdu 1281 棋盘游戏 (二分匹配)的更多相关文章
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
- hdu 1281 棋盘游戏 (二分匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 1281 棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 1281——棋盘游戏——————【最大匹配、枚举删点、邻接表方式】
棋盘游戏 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu 1281 棋盘游戏
http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 3468 BFS+二分匹配
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/10966383 开始建图打搓了,参考了大牛的题解打的版本比较清爽,后来改的基本雷同 ...
- HDU 2819 Swap (二分匹配+破输出)
题意:给定上一个01矩阵,让你变成一个对角全是 1 的矩阵. 析:二分匹配,把行和列看成两个集合,用匈牙利算法就可以解决,主要是在输出解,在比赛时一紧张不知道怎么输出了. 输出应该是要把 match[ ...
- D - 棋盘游戏 - HDU 1281(二分图匹配)
分析:先求出来最大匹配数,然后用匹配的点一个一个去除看看能否达到最大匹配,能的话就是关键点(很暴力啊),不过竟然才31ms ************************************** ...
- (step6.3.5)hdu 1281(棋盘游戏——二分图的完美匹配)
题目大意:本体是中文题.读者可以直接在OJ上看 解题思路: 1)完美匹配:所有的端点都是匹配点 2)对于二分图的完美匹配,我们需要用一个数组来存储匹配点.(而二分图的其他问题(我们则可以直接使用变量来 ...
随机推荐
- vim设置文本宽度
'textwidth' 'tw' number (default 0) local to buffer ...
- mysqldump 报导常
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transa ...
- mongoose中的versionKey
通过mongoose中的save方法保存记录时document文档默认最后会有一个字段"__v",这个字段表示该文档是否是刚刚创建的,如果是则字段"__v"的值 ...
- linux下调试core的命令
在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件的生成开 ...
- iOS-ARC-环境下如何查看引用计数的变化
iOS-ARC-环境下如何查看引用计数的变化 一,新建立一个工程,用于测试引用计数的变化. 二,找到如下路径Build Phases---->Compile Sources---->App ...
- 【转帖】漫话C++0x(四) —- function, bind和lambda
实在是觉得此文总是去翻感觉不太好.于是果断转过来了,想看原文的请戳:http://www.wuzesheng.com/?p=2032 本文是C++0x系列的第四篇,主要是内容是C++0x中新增的lam ...
- Along with all the above benefits, you cannot overlook the space efficiency and performance gains in using DataFrames and Dataset APIs for two reasons.
Of all the developers’ delight, a set of APIs that makes them productive, that are easy to use, and ...
- LeetCode: Populating Next Right Pointers in Each Node 解题报告
Populating Next Right Pointers in Each Node TotalGiven a binary tree struct TreeLinkNode { Tree ...
- c++之——template模板函数
为了实现与数据类型无关的编程,模板应运而生: #include<iostream> #include<string.h> using namespace std; templa ...
- python生成二维数组
Array= [[0 for i in range(15)] for i in range(15)]