Collation of game theory questions

Source: Internet
Author: User

In game theory, a very important conclusion is as follows:

If the previous status may all be defeated, the current status must be competitive.

If one of the previous states is a winning state, the current State must be a losing state.

 

Poj 2484 a funny game

In game games, the latter often takes advantage. Except that a can get all the light at a time, B can adopt the same strategy as a in other cases, so that each time the stones are divided into the same two groups, the final winner must be 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

Analyze the possible situations of each round (assume a> = B ):

When a-B <= B, the relationship can only be halved, that is, there is only one choice. In this way, the previous status is "win", and the current status is "fail". The previous status is "fail", and the current status is "win.

When a-B> B, assume there is a-xB <= B. There are many options at this time. Consider subtracting (x-1) B from A to arrive at the state, if this state is a defeat state, then the current state is a victory state. If this state is a winning state, the only a-(x-1) B reachable A-xB state is a defeated State, so at this time you can choose to subtract XB from A to win. Therefore, the current status must be competitive.

#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

 

You can participate in a tiered game.

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

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

Poj 1704

Step Nim, from right to left, the distance between each two pieces is regarded as a pile of stones, and the distance between the leftmost pieces and 0 is regarded as a pile of stones. In this way, you can perform a nim game on the stones in the odd heap.

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.