博弈刷题--威佐夫博弈及其变形

HDU1527

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{
    long long m, n;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        int temp;
        if(n > m)
        {
            temp = n;
            n = m;
            m = temp;
        }
        double w = (sqrt(5) + 1) / 2;
        int book = (m - n) * w;
        if(book == n)printf("0\n");
        else printf("1\n");
    }
    return 0;
}

HDU - 2177取(2堆)石子

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{
    int m, n;
    while(scanf("%d%d",&n,&m)!=EOF&&n&&m)
    {
        mapmapp;//去重
        double w = (sqrt(5) + 1.0) / 2.0;
        if((int)(w * (m - n)) == n)printf("0\n");
        else
        {
            printf("1\n");
            //int a, b;
            int m1 = m;
            for(int i = n - 1; i >= 0; i --)
            {
                m1 --;
                if((int)(w * (m1 - i)) == i)
                    printf("%d %d\n",i,m1);
            }
            //int temp;
            for(int i = m - 1; i >= 0; i --)
            {
                if((int)(w * abs(n - i)) == min(n, i) &&  mapp[min(n,i)] == 0)
                {
                    printf("%d %d\n",min(n,i),max(n,i));
                    mapp[min(n,i)] = max(n, i);
                }
            }
            for(int i = n - 1; i >= 0; i --)
            {
                if((int)(w * abs(m - i)) == i &&  mapp[i] == 0)
                {
                    printf("%d %d\n",i , m);
                    mapp[i] = m;
                }
            }

        }
    }
    return 0;
}

51Nod - 1072

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t --)
    {
        int m, n;
        scanf("%d%d",&n,&m);
        double k = (1+sqrt(5))/2;
        if((int)(k*abs(m-n)) == min(m, n))
            printf("B\n");
        else printf("A\n");
    }
    return 0;
}

51Nod - 1185

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
long long a[4] = {0, 618033988, 749894848, 204586834};//黄金分割数的小数点后27位保存起来
int main()
{
    int t;
    long long mod = 1e9;
    long long n, m, sum, k, fir, sec;
    scanf("%d",&t);
    while(t --)
    {
        scanf("%lld%lld",&n,&m);
        if(n > m) swap(n, m);
        k = m - n;
        fir = k / mod;//m-n的前九位
        sec = k % mod;//m-n的后九位
        sum = sec * a[3];//模拟乘法过程
        sum = fir * a[3] + sec * a[2] + sum / mod;
        sum = fir * a[2] + sec * a[1] + sum / mod;
        sum = fir * a[1] + sum / mod;
        sum += k;//因为乘的是黄金分割数,所以多减了一个自身,最后再加上
        if(sum == n) printf("B\n");
        else printf("A\n");
    }
    return 0;
}

 

你可能感兴趣的:(博弈论)