博弈论:Play a game - hdu1564

 

 

【题目大意】:

  ailyanlu 和 8600 在一块大小为 n*n的棋盘上下棋 , 8600 先手。

  棋盘上只有一颗旗子(初始的位置在角落。),每次操作都只能操作它。  

  每个选手每次都可以将棋子移动到 相邻的点上 ( 只要这个点之前没有到过 )。

  当一个人没法操作时,游戏结束,胜者是另一个人。求出赢的那个人是谁。

【思路】:

  除去棋子一开始占得点,只剩下n*n-1 个位置 。 当剩余位置为0 的时候,就是必败点。

  所以只要 n*n-1为奇数 ,这样就能把偶数情况留给对手,对手就只能必败。自己就必胜。

【代码】:

  

复制代码
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>

#define ms(a, b) memset(a,b,sizeof(a))
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define rep(i, a, b)  for(ll i=a;i<=b;i++)
#define lep(i, a, b)  for(ll i=a;i>=b;i--)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi  vector<ll>
#define vpi vector<pii>
#define vpl vector<pll>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define ff first
#define ss second
#define test4(x, y, z, a) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<"        a is "<<a<<endl;
#define test3(x, y, z) cout<<"x is "<<x<<"        y is "<<y<<"        z is "<<z<<endl;
#define test2(x, y) cout<<"x is "<<x<<"        y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
using namespace std;
const int N = 1e5 + 10;
const int maxx = 0x3f3f3f;
const int mod = 1e9 + 7;
const int minn = -0x3f3f3f;
const int M = 2 * N;
ll T, n, m;

void solve() {
    if ( (n*n-1) % 2 == 1 ) cout<<"8600"<<endl;
    else cout<<"ailyanlu"<<endl;

}

int main() {
    fast;
    while ( 1 ){
        cin>>n;
        if ( n==0 ) break;
        solve();
    }
    return 0;
}
View Code
复制代码

 

posted @   Pan_c  阅读(58)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示