POJ2599 A funny game (圖博弈),poj2599funny

來源:互聯網
上載者:User

POJ2599 A funny game (圖博弈),poj2599funny

題目連結:傳送門

題意:

給定一個圖,兩個人從起點出發,輪流開飛機,當離開這個點後這個點

就不能使用了,如果輪到誰了誰不能飛了就輸了。

必敗狀態很好找,當一個人在位置s的時候與這個點相連的沒有點能用的

時候則必敗。然後資料很小,直接暴力搜尋就可以AC。

代碼如下:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <set>#include <map>#include <queue>#define PB push_back#define MP make_pair#define REP(i,n) for(int i=0;i<(n);++i)#define FOR(i,l,h) for(int i=(l);i<=(h);++i)#define DWN(i,h,l) for(int i=(h);i>=(l);--i)#define IFOR(i,h,l,v) for(int i=(h);i<=(l);i+=(v))#define CLR(vis) memset(vis,0,sizeof(vis))#define MST(vis,pos) memset(vis,pos,sizeof(vis))#define MAX3(a,b,c) max(a,max(b,c))#define MAX4(a,b,c,d) max(max(a,b),max(c,d))#define MIN3(a,b,c) min(a,min(b,c))#define MIN4(a,b,c,d) min(min(a,b),min(c,d))#define PI acos(-1.0)#define INF 1000000000#define LINF 1000000000000000000LL#define eps 1e-8#define LL long longusing namespace std;const int maxn = 1001;int mp[maxn][maxn];bool vis[maxn];int ans,n,s;bool dfs(int id){    FOR(i,1,n){        if(mp[id][i]&&!vis[i]){//遍曆圖的順序確保了答案最小            vis[id]=1;            if(!dfs(i)){                vis[id]=0;                ans=i;                return true;            }        }        vis[id]=0;    }    return false;}int main(){    while(~scanf("%d%d",&n,&s)){        CLR(mp);        REP(i,n-1){            int u,v;            scanf("%d%d",&u,&v);            mp[u][v]=1;            mp[v][u]=1;        }        CLR(vis);        if(dfs(s)) printf("First player wins flying to airport %d\n",ans);        else puts("First player loses");    }    return 0;}


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.