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 ...
随机推荐
- mysql 使用过程中出现问题
1. mysql_front连接报错,sql执行错误#3167的解决方案 提示:The 'INFORMATION_SCHEMA.SESSION_VARIABLES' feature is disabl ...
- maven建ssh项目的pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示
Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示 在 开发中遇到应用c#及asp.net的在的webservice 保存图片并以xml文件形式现实出来 ...
- 自定义响应结构 AjaxResult()
package com.dsj.gdbd.utils.ajax; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxm ...
- message消息框
.messager.show options 在屏幕右下角显示一条消息窗口.该选项参数是一个可配置的对象:showType:定义将如何显示该消息.可用值有:null,slide,fade,show.默 ...
- 前端多媒体(7)—— 在浏览器中实现rtmp推流
示例:https://young-cowboy.github.io/gallery/rtmp_client/index.html 在国内的直播场景中通常使用,rtmp协议作为推流协议.RTMP是Rea ...
- HTML5视音频标签参考
本文将介绍HTML5中的视音频标签和对应的DOM对象.是相关资料的中文化版本,可以作为编写相关应用的简易中文参考手册. 一些约定 所有浏览器:指支持HTML5的常见桌面浏览器,包括IE9+.Firef ...
- TVYJ1266:费解的开关
我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:http://www.joyoi.cn/problem/tyvj-1266 这 ...
- android开发 解析服务器端xml文件数据存储到android客户端SQLite数据库
以下面xml文件为例对其解析(假设此xml就在服务器端Server项目下的servlet包下的MenuServlet文件的输出流中): <?xml version="1.0" ...
- MySQL5.7出现Your password has expired. To log in you must change it using a client that supports expir
今天晚上本来想写bootstrap-fileinput插件集成fastdfs的文章,但是刚启动idea里面的QiYuAdmin就出现了错误: Your password has expired. To ...