CodeForces 116B【二分匹配】
思路:
暴力。。我不会呀。。
YY一个二分匹配嘛,然后数组开小了。GG for an hour.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL; int cy[110];
int cx[110];
int n,m;
char ma[15][15];
int g[15][15];
int mma[110][110]; int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1}; bool vis[110]; int findpath(int u)
{
for(int i=1;i<=m;i++)
{
if(!vis[i]&&mma[u][i])
{
vis[i]=1;
if(cy[i]==-1||findpath(cy[i]))
{
cy[i]=u;
cx[u]=i;
return 1;
}
}
}
return 0;
} int main()
{
int x,y;
n=m=0;
memset(g,0,sizeof(g));
scanf("%d%d",&x,&y);
for(int i=0;i<x;i++)
{
scanf("%s",ma[i]);
for(int j=0;j<y;j++)
{
if(ma[i][j]=='P')
g[i][j]=++m;
if(ma[i][j]=='W')
g[i][j]=++n;
}
} for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
if(ma[i][j]=='W')
{
int ss=g[i][j];
for(int k=0;k<4;k++)
{
int xx=i+dx[k];
int yy=j+dy[k];
if(xx<0||yy<0||xx>=x||yy>=y)
continue;
if(ma[xx][yy]=='P')
{
int tt=g[xx][yy];
mma[ss][tt]=1;
}
}
}
}
}
memset(cx,-1,sizeof(cx));
memset(cy,-1,sizeof(cy));
int ans=0;
for(int i=1;i<=n;i++)
{
if(cx[i]==-1)
{
memset(vis,0,sizeof(vis));
ans+=findpath(i);
}
}
printf("%d\n",ans);
return 0;
} /*
3 10
WPPP...PP.
.P...WW..W
.WWP.PP.PW
*/
CodeForces 116B【二分匹配】的更多相关文章
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
- UVA5874 Social Holidaying 二分匹配
二分匹配简单题,看懂题意,建图比较重要. #include<stdio.h> #include<string.h> #define maxn 1100 int map[maxn ...
随机推荐
- java: jdk1.8以后就不支持桥接的方式
java: jdk1.8以后就不支持桥接的方式 如果想继续使用桥接的方式,请使用jdk1.7及以下版本.
- hdu--2570--迷瘴(贪心)
#include<iostream> #include<vector> #include<algorithm> using namespace std; int m ...
- JNI简易入门
JNI简介 JNI(Java Native Interface)是JDK的一部分,提供了若干API实现了Java和其他语言的通信(主要是C/C++).JNI主要用于以下场景: 贴近硬件底层的功能,Ja ...
- P2056 采花
题目描述 萧芸斓是 Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了 n 朵花,花有 c 种颜色(用整数 1-c 表示) ,且花是排成 ...
- JAVA JDBC 读取配置文件链接数据库(oracle)
----db.properties-------- dbDriver = oracle.jdbc.driver.OracleDriverurl = jdbc:oracle:thin:@192.168. ...
- 洛谷【P1104】生日(选择排序版)
题目传送门:https://www.luogu.org/problemnew/show/P1104 题目很简单,不过我是来讲选择排序的. 选择排序\((Selection sort)\)是一种简单直观 ...
- EF中调整字段的顺序
EF中设计数据库表结构时,在Designer UI中无法调整添加好的字段顺序. 方法: 1.在Solution Explorer中右击XXX.edmx文件, 选择"Open With&quo ...
- HDU1114(完全背包装满问题)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- virtual judge(专题一 简单搜索 E)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- 转载:PLSQL Developer使用技巧整理
Shortcut(快捷方式): Edit/Undo Ctrl+Z Edit/Redo Shift+Ctrl+Z Edit/PL/SQL Beautifier Ctrl+W (自定 ...