2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

本文介绍了一种基于博弈论的游戏算法实现,通过分析奇数和偶数位数的特性来判断游戏状态,进而决定游戏胜负。文章展示了如何利用C++进行高效编程,包括初始化全局变量、定义关键函数等步骤,并提供了完整的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



G,H

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>

using namespace std;

#define REP(a,b,c) for(int a = b; a < c; ++a)
#define MAXN 210

const int MAX_ = 500010;
const int INF = 0x7fffffff;
const int N = 500010;


int dp[MAX_];

void init(){
    int n = 100001;
    dp[0] = 0;
    REP(i, 1, n){
        int tmp, cnt = 0, num = 0;
        tmp = i;
        while(tmp){
            if(tmp%10 == 7)cnt++;
            num++;
            tmp /= 10;
        }
        if(num-cnt<=1)dp[i] = dp[i-1]+1;
        else dp[i] = dp[i-1];
    }
}

int lowbit(int x){return x&(-x);}

bool run(int n, int m){
    if((n&1) && (m&1)){
        return false;
    }
    if(!(n&1) && !(m&1)){
        int cnt;
        cnt = lowbit(n) + lowbit(m);
        if(cnt&1)return true;
        else return false;
    }

    int x;
    if(n&1)x = m;
    else x = n;

    int cnt = lowbit(x) - 1;

    //printf("cnt = %d\n",cnt);
    if(cnt&1)return true;
    else return false;
}

int main(){
    //init();
    int T, s, t, Ca = 1;
    //memset(dp, -1, sizeof dp);
    scanf("%d",&T);
    while(T--){

        scanf("%d%d", &s, &t);
        printf("Case %d: ",Ca++);
        bool flag = run(s, t);
        if(flag){
            printf("Alice\n");
        }
        else printf("Bob\n");
        /*scanf("%d",&s);


        printf("%d\n",dp[s]);*/
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值