HDU 5708 Alice and Bob (博弈,找规律)

题意: 一个无限大的棋盘,一开始在1,1,有三种移动方式,(x+1,y)(x,y+1) (x+k,y+k)最后走到nm不能走了的人算输。。

析:。我们看成一开始在(n,m),往1,1,走,所以自然可以从1,1,开始递推往出,那么打表程序就出来了。。

打出表以后我们观察到k等于1时稍有特殊,其他则与  (min(cx,cy)&1)^((n+m)&1)) 有关ps(其中cx=n/(k+1),cy=m/(k+1))

那么就愉快的分类讨论外加试一试和表对照一下就好了。。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2000 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
//int n, m;
int n,m,k,q;

void print(int x){
    cout << (x == 1 ? "Alice" : "Bob") << endl;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        cin >> q >> k;
        while(q--){
            cin >> n >> m;
            int cx = n/(k+1), cy = m / (k+1);
            int yx = n % (k+1), yy = m % (k+1);
            if(k == 1){
                if((yx == 0 && m >= n) || (yy == 0 && n >= m)) print(1);
                else  print((0^((n+m)&1)));
            }
            else{
                if((yx == 0 && m >= n) || (yy == 0 && n >= m)) print(1);
                else print((0^(min(cx,cy)&1)^((n+m)&1)));
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5719526.html