[JSOI2009]游戏Game
Time Limit:10000MS Memory Limit:165536K
Total Submit:21 Accepted:12
Case Time Limit:1000MS
Description
Input
输入数据首先输入两个整数N,M,表示了迷宫的边长。
接下来N行,每行M个字符,描述了迷宫。
Output
若小AA能够赢得游戏,则输出一行"WIN",然后输出所有可以赢得游戏的起始位置,按行优先顺序输出
每行一个,否则输出一行"LOSE"(不包含引号)。
Sample Input
3 3
.##
…
#.#
Sample Output
2 3
3 2
Hint
对于100%的数据,有1≤n,m≤100。
对于30%的数据,有1≤n,m≤5。
Source
JSOI2009Day2
这题好那个啥囧。。。2个月前见到此题毫无思路。。。
然后上个星期突然有一点思路了。。
然后又考虑了N久。。。
(其实是看到了一道数学题,就是(2n+1)*(2n+1)的正方形上求证放的人有必胜策略,这个题目随便放在一个点上,然后吧其它的点按多米诺骨牌配对,然后每次别人走到一个点上我就到配对的那个点上。。。肯定赢。。。)
然后接着想。。那么这个是不是也跟最大匹配有关系呢。。。
想了很久秃然明白了囧。。。
如果一个点一定在最大匹配里。。。
所以从这点出发的交替路肯定只能到达匹配中的点。。
那么每次我都肯定可以顺着匹配边走。。。别人就被我搞死了。。。
如果一个点可以不在最大匹配里。。
那么在那个图里面。。。对方每次顺着匹配边走。。我就被搞死了。。。
所以只需要知道每个点是否可以不在最大匹配里。。。
一开始我直接暴力。。TLE。。
后来发现可以不在的点其实就是当前从vs可达的之类的。。。
就可以A了。。速度爆慢囧。。
Code:
#include <vector>
#include <algorithm>
#include <utility>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define tr(e,x) for(vector<int>::iterator e=x.begin();e!=x.end();e++)
#define All(x) x.begin(),x.end()
#define pb push_back
#define OK puts("OK")
const int inf=~0U>>1,maxn=100,maxv=maxn*maxn+10;
using namespace std;
struct Edge
{
int t,c;
Edge*next,*op;
Edge(int _t,int _c,Edge*_n):
t(_t),c(_c),next(_n){}
}*E[maxv]={};
void AddEdge(int s,int t,int c)
{
E[s]=new Edge(t,c,E[s]);
E[t]=new Edge(s,0,E[t]);
E[s]->op=E[t];E[t]->op=E[s];
}
int n,m,v,vs,vt;
bool M[maxn][maxn];
void BuildGraph()
{
v=n*m;vs=v++;vt=v++;
rep(i,n)rep(j,m)
if(M[i][j])
if((i+j)&1)
{
#define A(i,j) ((i)*m+(j))
#define build(ii,jj)
if(M[ii][jj])
AddEdge(A(i,j),A(ii,jj),1)
AddEdge(vs,A(i,j),1);
if(i)build(i-1,j);
if(j)build(i,j-1);
if(i+1<n)build(i+1,j);
if(j+1<m)build(i,j+1);
#undef build
}
else
{
AddEdge(A(i,j),vt,1);
#undef A
}
}
int Vis[maxv]={},flag=0;
int dfs(int x,int m)
{
if(x==vt)return m;
Vis[x]=flag;
for(Edge*e=E[x];e;e=e->next)if(e->c&&Vis[e->t]!=flag)
{
int d=dfs(e->t,min(m,e->c));
if(d) return e->c-=d,e->op->c+=d,d;
}
return 0;
}
void Init()
{
scanf("%d%d",&n,&m);char c;
rep(i,n)
{
scanf(" ");
rep(j,m)
c=getchar(),M[i][j]=c==’.';
}
}
bool dead[maxv]={},type;
bool Type(int v)
{
return (v%m+v/m)&1;
}
int C;
void dfs(int x)
{
Vis[x]=flag;
if(Type(x)==type)
dead[x]=true;
for(Edge*e=E[x];e;e=e->next)
if(e->c==type&&Vis[e->t]!=flag)
dfs(e->t);
}
void Solve()
{
++flag;int Max=0;
while(int d=dfs(vs,inf))++flag,Max+=d;
++flag;
type=1;
dfs(vs);dead[vs]=false;
++flag;
type=0;
dfs(vt);dead[vt]=false;
bool has=false;
rep(i,v)if(dead[i]){has=true;break;}
if(has)
{
puts("WIN");
rep(i,v)if(dead[i])
{
int x=i/m,y=i%m;
printf("%d %dn",x+1,y+1);
}
}
else
{
puts("LOSE");
}
}
int main()
{
//freopen("in","r",stdin);
Init();
BuildGraph();
Solve();
}
膜拜!!!!!!!我至今都不会捉
This problem is so hard that I did about 2 hours on it and got a 0…………= =|||
膜拜 可以这样求>_<
膜拜神牛!
我擦!
!!!!!!!!!1
膜拜!!!
ym
Wow, wonderful blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your site is wonderful, let alone the content!
we prefer to honor many other web web sites on the net, even when they arent linked to us, by linking to them. Below are some webpages worth checking out
below youll discover the link to some web pages that we assume you ought to visit
that would be the finish of this article. Here you will find some internet sites that we feel youll value, just click the hyperlinks over
that would be the end of this report. Here youll come across some web sites that we feel youll enjoy, just click the hyperlinks over
always a massive fan of linking to bloggers that I adore but dont get a lot of link appreciate from
that may be the end of this write-up. Here you will find some web-sites that we consider youll appreciate, just click the hyperlinks over
below youll locate the link to some web-sites that we think you need to visit
usually posts some incredibly fascinating stuff like this. If youre new to this site
that could be the end of this report. Right here you will come across some internet sites that we believe youll appreciate, just click the hyperlinks over
below youll find the link to some internet sites that we feel it is best to visit
usually posts some incredibly intriguing stuff like this. If youre new to this site
below youll locate the link to some internet sites that we consider you need to visit
usually posts some quite interesting stuff like this. If youre new to this site
we like to honor a lot of other world-wide-web web pages on the internet, even if they arent linked to us, by linking to them. Underneath are some webpages really worth checking out
that will be the end of this report. Here youll discover some web pages that we consider youll enjoy, just click the hyperlinks over
we prefer to honor numerous other online websites around the internet, even when they arent linked to us, by linking to them. Beneath are some webpages worth checking out
that will be the finish of this post. Here you will obtain some web-sites that we consider youll value, just click the links over
below youll obtain the link to some web sites that we believe you’ll want to visit
always a big fan of linking to bloggers that I really like but dont get lots of link adore from
we prefer to honor a lot of other net web-sites on the internet, even when they arent linked to us, by linking to them. Under are some webpages really worth checking out
we like to honor lots of other web internet sites on the internet, even if they arent linked to us, by linking to them. Beneath are some webpages really worth checking out
always a significant fan of linking to bloggers that I really like but dont get a lot of link really like from
usually posts some really exciting stuff like this. If youre new to this site
we like to honor numerous other internet web sites around the net, even though they arent linked to us, by linking to them. Beneath are some webpages worth checking out
we prefer to honor numerous other web internet sites around the net, even though they arent linked to us, by linking to them. Underneath are some webpages worth checking out
always a huge fan of linking to bloggers that I appreciate but dont get a good deal of link really like from
we like to honor lots of other online websites on the net, even when they arent linked to us, by linking to them. Beneath are some webpages really worth checking out
we like to honor several other world-wide-web web-sites around the net, even if they arent linked to us, by linking to them. Beneath are some webpages worth checking out
that will be the end of this write-up. Right here you will obtain some web pages that we consider youll enjoy, just click the hyperlinks over
we like to honor quite a few other world wide web internet sites on the web, even when they arent linked to us, by linking to them. Under are some webpages worth checking out
below youll come across the link to some sites that we consider you ought to visit
that will be the finish of this post. Right here youll come across some web sites that we consider youll value, just click the links over
always a significant fan of linking to bloggers that I love but dont get a whole lot of link like from
we prefer to honor a lot of other net internet sites around the web, even if they arent linked to us, by linking to them. Below are some webpages really worth checking out
that will be the end of this write-up. Right here youll discover some internet sites that we consider youll enjoy, just click the links over
Always a big fan of linking to bloggers that I like but dont get quite a bit of link enjoy from.
that may be the finish of this article. Here youll uncover some web pages that we consider you will enjoy, just click the links over
below youll find the link to some websites that we assume you ought to visit
that will be the end of this write-up. Right here youll locate some internet sites that we consider you will appreciate, just click the hyperlinks over
we like to honor many other web web-sites around the internet, even though they arent linked to us, by linking to them. Under are some webpages really worth checking out
below youll obtain the link to some internet sites that we feel you’ll want to visit
that will be the finish of this write-up. Here youll locate some web-sites that we feel youll enjoy, just click the hyperlinks over