HDU 2177

http://acm.hdu.edu.cn/showproblem.php?pid=2177

威佐夫博奕,面对奇异局势既bk=ak+k时是必败点,其中bk>=ak,k=bk-ak

别的处理和其他博弈相同,注意题目的数据取一堆的时候数据有问题

#include <iostream>

#include <cstdio>

#include <cmath>

#include <map>



using namespace std;

 

int OK(int b, int k) {

    if(b == (int)(k * (1 + sqrt(5.0)) / 2) + k) return 1;

    return 0;

}

 

int main() {

    int a, b;

    while(~scanf("%d%d", &a, &b)) {

        if(!a && !b) break;

        if(a > b) swap(a, b);

        int k = b - a;

        if(OK(b, k)) puts("0");

        else {

            puts("1");

            int x, y;

            for(int i = 1; i <= a; i++) {

                x = a - i, y = b - i;

                if(OK(y, y-x)) printf("%d %d\n", x, y);

            }

            map <int, int> mp;

            for(int i = 1; i <= b; i++) {

                x = a - i, y = b;

                if(x > 0 && OK(y, y-x) && mp[x]!=y) {

                    printf("%d %d\n", x, y);

                    mp[x] = y;

                }

                x = a, y = b - i;

                if(x > y) swap(x, y);

                if(OK(y, y-x) && mp[x]!=y) {

                    printf("%d %d\n", x, y);

                    mp[x] = y;

                }

            }

        }

    }

    return 0;

}
View Code

 

你可能感兴趣的:(HDU)