博弈論 題目整理

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   

博弈論裡面一個非常重要的結論:

如果前一個狀態所有可能都是必敗態,那麼目前狀態一定是必勝態。

如果前一個狀態所有可能有一個是必勝態,那麼目前狀態一定是必敗態。

 

POJ 2484 A Funny Game

博弈遊戲裡面後手經常佔據優勢。除了A可以一次性全部拿光的情況,其他時候B都可以採取與A相同的策略,這樣每次將石子分為相同的兩組,最後獲勝的一定是B。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){    int n;    while(scanf("%d",&n)&&n)    {        if(n<=2) puts("Alice");        else puts("Bob");    }    return 0;}
View Code

 

POJ 2348

分析每回合可能的情況,(假設a>=b):

當a-b<=b時,這個時候只能減去1倍關係,也就是只有唯一選擇。這樣,前一個狀態是必勝,那麼當前就是必敗;前一個狀態是必敗,當前就是必勝。

當a-b>b時,假設此時有a-xb<=b。這時候有很多種選擇。考慮從a中減去(x-1)b到達的狀態,如果該狀態是必敗態,那麼目前狀態就是必勝態。如果該狀態是必勝態,那麼a-(x-1)b唯一可達的a-xb狀態是必敗態,所以這個時候可以選擇從a中減去xb來獲勝。所以目前狀態一定是必勝態。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){    int a,b;    while(scanf("%d%d",&a,&b)&&!(!a&&!b))    {        int c=0;        while(1)        {            if(a<b) swap(a,b);            if(a%b==0) break;            if(a-b<=b) a=a-b;            else break;            c++;        }        if(c%2==1) puts("Ollie wins");        else puts("Stan wins");    }    return 0;}
View Code

 

關於階梯博弈可以參加

http://blog.csdn.net/kk303/article/details/6692506

http://www.cnblogs.com/jiangjing/p/3849284.html

POJ 1704

階梯NIM,從右往左,每兩個棋子的距離視為一堆石子,最左邊的棋子與0的距離視為一堆石子。這樣對第奇數堆的石子做NIM遊戲處理即可。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){    int T;    scanf("%d",&T);    while(T--)    {        int n;        int p[1005]= {0};        scanf("%d",&n);        for(int i=1; i<=n; ++i)            scanf("%d",&p[i]);        sort(p,p+1+n);        int ans=0;        for(int i=n; i-1>=0; i-=2)            ans=ans^(p[i]-p[i-1]-1);        if(ans!=0) puts("Georgia will win");        else puts("Bob will win");    }    return 0;}
View Code

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.