http://acm.hdu.edu.cn/showproblem.php?pid=3446

题意:一个棋盘,有个KING,有一些能走的点,每次只能走到没走过的地方,没路可走的输,求先手是否必胜。

思路:先去掉KING的位置,只考虑其他的,如果这样求出的匹配数和加上king的匹配数一样,说明KING这个位置没有在匹配中,因此后手必胜,否则先手必胜,为什么?

可以思考一下,匹配的路径是一条:匹配,不匹配,匹配。。。不匹配,匹配,因此如果KING在匹配中,那最后一步也能够是先手走的。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
int dx[]={-,-,-,,,,,,,-,,-,,-,,-,,-,-,};
int dy[]={-,,,,,-,-,,,,-,-,,-,-,,,-,,-};
int match[],G[][],inpath[],q[],head,tail,newbase;
int inqueue[],inblossom[],base[],father[],n;
int finish,start,R,C,kx,ky,c[];
char s[][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int lca(int u,int v){
memset(inpath,,sizeof inpath);
while (){
u=base[u];
inpath[u]=;
if (!match[u]) break;
u=father[match[u]];
}
while (){
v=base[v];
if (inpath[v]) break;
v=father[match[v]];
}
return v;
}
void reset(int u){
while (u!=newbase){
int v=match[u];
inblossom[base[v]]=inblossom[base[u]]=;
u=father[v];
if (base[u]!=newbase) father[u]=v;
}
}
void blossomcontract(int u,int v){
newbase=lca(u,v);
memset(inblossom,,sizeof inblossom);
reset(u);
reset(v);
if (base[u]!=newbase) father[u]=v;
if (base[v]!=newbase) father[v]=u;
for (int i=;i<=n;i++)
if (inblossom[base[i]]){
base[i]=newbase;
if (!inqueue[i]) c[++tail]=i,inqueue[i]=;
}
}
void findaugmentingpath(){
memset(inqueue,,sizeof inqueue);
memset(father,,sizeof father);
for (int i=;i<=n;i++) base[i]=i;
head=;tail=;c[]=start;inqueue[start]=;
finish=;
while (head<=tail){
int u=c[head++];
for (int v=;v<=n;v++)
if (G[u][v]&&base[u]!=base[v]&&match[v]!=u){
if (v==start||(match[v]>)&&(father[match[v]]>)){
blossomcontract(u,v);
}else
if (father[v]==){
father[v]=u;
if (match[v]){
c[++tail]=match[v];inqueue[match[v]]=;
}else{
finish=v;
return;
}
}
}
}
}
void augmentpath(){
int u,v,w;
u=finish;
while (u>){
v=father[u];
w=match[v];
match[u]=v;
match[v]=u;
u=w;
}
}
int solve(){
int res=;
memset(match,,sizeof match);
for (int i=;i<=n;i++)
if (!match[i]){
start=i;
findaugmentingpath();
if (finish) augmentpath(),res++;
}
return res;
}
int main(){
int T=read(),Tcase=;
while (T--){
printf("Case #%d: daizhenyang ",++Tcase);
R=read();C=read();
memset(G,,sizeof G);
for (int i=;i<=R;i++){
scanf("%s",s[i]+);
}
for (int i=;i<=R;i++)
for (int j=;j<=C;j++)
if (s[i][j]!='#'){
for (int k=;k<;k++){
int x=i+dx[k],y=j+dy[k];
if (x>=&&x<=R&&y>=&&y<=C&&s[x][y]!='#'){
G[(i-)*C+j][(x-)*C+y]=;
G[(x-)*C+y][(i-)*C+j]=;
}
}
if (s[i][j]=='K') kx=i,ky=j;
}
n=R*C;
int t1=solve();
int x=(kx-)*C+ky;
for (int i=;i<=n;i++) if (G[x][i]) G[x][i]=G[i][x]=;
if (solve()==t1) puts("lose");
else puts("win");
}
return ;
}

HDU 3446 daizhenyang's chess的更多相关文章

  1. HDU 5794 - A Simple Chess

    HDU 5794 - A Simple Chess题意: 马(象棋)初始位置在(1,1), 现在要走到(n,m), 问有几种走法 棋盘上有r个障碍物, 该位置不能走, 并规定只能走右下方 数据范围: ...

  2. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  3. HDU 5794 A Simple Chess (容斥+DP+Lucas)

    A Simple Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 Description There is a n×m board ...

  4. HDU 5794 A Simple Chess dp+Lucas

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5794 A Simple Chess Time Limit: 2000/1000 MS (Java/O ...

  5. 【HDU】4405 Aeroplane chess

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:每次可以走1~6格,初始化在第0格,走到>=n的格子就结束.还有m个传送门,表示可以从X[i] ...

  6. HDU 5794 A Simple Chess (Lucas + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5794 多校这题转化一下模型跟cf560E基本一样,可以先做cf上的这个题. 题目让你求一个棋子开始在( ...

  7. HDU 3537 Daizhenyang's Coin

    链接 [http://acm.hdu.edu.cn/showproblem.php?pid=3537] 题意 题意:已知一排硬币中有n个硬币正面朝上,输入正面朝上的硬币的位置ai.两人轮流操作, 每次 ...

  8. HDU 3537 Daizhenyang's Coin(博弈,翻硬币)

    Daizhenyang's Coin Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. HDU 5794 A Simple Chess Lucas定理+dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5794 题意概述: 给出一个N*M的网格.网格上有一些点是障碍,不能经过.行走的方式是向右下角跳马步.求 ...

随机推荐

  1. POJ 2075 Tangled in Cables (c++/java)

    http://poj.org/problem?id=2075 题目大意: 给你一些人名,然后给你n条连接这些人名所拥有的房子的路,求用最小的代价求连接这些房子的花费是否满足要求. 思路: 昨天20分钟 ...

  2. MYSQL 体系结构图-LRU FREELIST FLUSH LIST

  3. HTML中常见的各种位置距离以及dom中的坐标讨论

    最近在学习JavaScript,特意买了一本犀牛角书来看看,尼玛一千多页,看的我头昏脑涨,翻到DOM这章节,突然记起平常在使用DOM时,碰到了好多的这个dom里面的各种宽度,高度,特意在此写一写,写的 ...

  4. Delpoyment assembly

    遇见异常: java.lang.ClassNotFoundException: 原因:没有对tomcat进行依赖说明 解决: properties - Delpoyment assembly 将tom ...

  5. linux 之 yum 介绍 <转>

    原文在这里  http://doophp.sinaapp.com/archives/linux/yum-setting-parameter.html 因为是程序员出身,平时虽然经常接触服务器,偶尔也会 ...

  6. python环境准备

    一.环境准备. 1.安装python3.5.2(勾选环境变量),python2.7.12 2.设置环境变量 (要求命令行输入python,进入python2命令行,打python3时,进入python ...

  7. windows安装服务

    我安装了windows服务的时候监控其他机子的时候,我在调试的时候用的是Account是其他用户是可以正常的,但是安装成服务的时候,老是被拒绝. 后来我将Account改成NetworkService ...

  8. require.js的使用的坑!

    require.js的使用心德: 都是自我的理解所得: first:为什么使用? 1,web开发js的占用比例越来越大,引入的插件也越来越多,维护困难,一个一个的script的写要废 2,模块开发的需 ...

  9. APP长时间处于后台,再次调用时提示用户重新登录

    第一步:当应用被处于后台时,调用计时器的start()方法,开始计时 在所有Activity继承的BaseSwiBackAct中的 public void onStop() { EventBus.ge ...

  10. Android之使用json进行网络数据交换

    JSON作为一种轻量级的数据交换格式,凭借其易于阅读和编写.易于解析.传输速度快等优点流行了起来.最近正好在学习Android端从服务端端取数据,Json便派上了用场.好,下面开始切入主题. 1.准备 ...