lightoj 1296 - Again Stone Game 博弈论
思路:由于数据很大,先通过打表找规律可以知道,
当n为偶数的时候其SG值为n/2;
当n为奇数的时候一直除2,直到为偶数m,则SG值为m/2;
代码如下:
#include<stdio.h>
int cal(int m)
{
while(m&) m>>=;
return m>>;
}
int main()
{
int t,n,ca=,a;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int ans=;
for(int i=;i<n;i++){
scanf("%d",&a);
ans^=cal(a);
}
printf("Case %d: %s\n",++ca,ans?"Alice":"Bob");
}
return ;
}
lightoj 1296 - Again Stone Game 博弈论的更多相关文章
- LightOJ 1296 Again Stone Game(sg函数)题解
题意:每次必须拿且只能拿不超过一半的石头,不能拿为败 思路:显然算出每个的sg函数,但是范围1e9显然不能直接打表.所以先打表找规律,发现偶数一直是自己的一半,奇数好像没规律.偶数x的sg函数值是x/ ...
- [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)
[Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
F - Again Stone Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- UVa 1378 A Funny Stone Game [博弈论 SG函数]
A Funny Stone Game 题意: $n \le 23$堆石子,每次选择$i < j \le k$,从$i$拿走1颗$j,k$各放入一颗,不能取就失败.求先手是否必胜以及第一次取的策略 ...
- hdu 2486/2580 / poj 3922 A simple stone game 博弈论
思路: 这就是K倍动态减法游戏,可以参考曹钦翔从“k倍动态减法游戏”出发探究一类组合游戏问题的论文. 首先k=1的时候,必败态是2^i,因为我们把数二进制分解后,拿掉最后一个1,那么会导致对方永远也取 ...
- hdu 1729 Stone Game 博弈论
那么对于这题对于每一堆,放石子放满就想当于满的时候取s-c个,反向只是让我理解题意更深. 首先我们知道(S,S)这个局面是必败局面.对于每一堆能加的数量有限,而当c的值(大于或者等于) D=sqrt( ...
- 【POJ】A New Stone Game(博弈论)
http://poj.org/problem?id=1740 题目大意就是,对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分 ...
- 博弈论(男人八题):POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5694 Accepted: 3119 ...
- Light OJ 1296:Again Stone Game(SG函数打表找规律)
Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains ...
随机推荐
- node、npm及node_modules中依赖的版本更新
好久没用node了,想重新拾起来发现node还有相关模块的版本都太低了,使用npm install全是报版本低的警告. 这里记录一下,版本管理和node_modules更新的方法. 我用的是Windo ...
- VueJS 轻松支持 JSX 配置
使用: babel-preset-vue-app TODO
- BeanPostProcessor的五大接口
BeanPostProcessor 关于对象初始化前后的回调. public interface BeanPostProcessor { //该方法在bean实例化完毕(且已经注入完毕),在after ...
- 深入理解Spring系列之二:BeanDefinition解析
转载 https://mp.weixin.qq.com/s?__biz=MzI0NjUxNTY5Nw==&mid=2247483814&idx=1&sn=ddf49931d55 ...
- oracle imp dmp命令
vi par.txt userid=system/oracle tables=(user.table,...) query="where org_no like 32%" file ...
- django 项目中的 favicon.ico 处理
django 项目中的 favicon.ico 处理 (django == 2.0.6) 1. 引入模块: from django.views.generic.base import Redirec ...
- 当array_filter函数的callback留空时 他会过滤掉所有键值为false的键
当array_filter函数的callback留空时 他会过滤掉所有键值为false的键
- C# 多线程多文件批量下载---子线程中更新UI 实例
代码1: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;usi ...
- Linux自身安全SElinux
查看SELinux状态: 1./usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态 SELinux status: ...
- beego学习笔记(3)
相对复杂一点的示例: package main import "github.com/astaxie/beego" type MainController struct{ beeg ...