UVaLive5059 Playing With Stones
数学问题 博弈 SG函数
我总觉得这题做过的……然而并没有记录
看上去是一个nim游戏的模型。
手推/打表找一下前几项的规律,发现x是偶数时,sg[x]=x/2,x是奇数时,sg[x]=sg[x div 2]
差点看漏了数据范围是1e18
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
LL SG(LL x){
if(x%==)return x/;
else return SG(x/);
}
int main(){
int i,j;LL x;
int T=read();
while(T--){
LL res=;
n=read();
for(i=;i<=n;i++){
x=read();
res^=SG(x);
}
if(res)printf("YES\n");
else printf("NO\n");
}
return ;
}
UVaLive5059 Playing With Stones的更多相关文章
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
C - Playing With Stones Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu S ...
- UVA 1482 - Playing With Stones(SG打表规律)
UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...
- LA 5059 - Playing With Stones
博弈 SG 由于每个a太大,没有办法递推,但是可以找规律 a为偶数 SG(a)=a/2 a为奇数 SG(a)=SG(a/2) 代码: #include <iostream> #inc ...
- LA 5059 (找规律 SG函数) Playing With Stones
题意: 有n堆石子,两个人轮流取,每次只能取一堆的至少一个至多一半石子,直到不能取为止. 判断先手是否必胜. 分析: 本题的关键就是求SG函数,可是直接分析又不太好分析,于是乎找规律. 经过一番“巧妙 ...
- uva 1482 - Playing With Stones
对于组合游戏的题: 首先把问题建模成NIM等经典的组合游戏模型: 然后打表找出,或者推出SG函数值: 最后再利用SG定理判断是否必胜必败状态: #include<cstdio> #defi ...
- uva1482:Playing With Stones (SG函数)
题意:有N堆石子,每次可以取一堆的不超过半数的石子,没有可取的为输. 思路:假设只有一堆,手推出来,数量x可以表示为2^p-1形式的必输. 但是没什么用,因为最后要的不是0和1,而是SG函数:所以必输 ...
- LA5059 Playing With Stones
题意:nim游戏.加上限制每次不得取走超过当前堆一半的石子 1 ≤ N ≤ 100,1 ≤ ai ≤ 2 ∗ 1018 分析:由于ai过大.所以我们采用SG函数递推找规律. (详见代码) #inclu ...
- 【LA5059】Playing With Stones (SG函数)
题意:有n堆石子,分别有a[i]个.两个游戏者轮流操作,每次可以选一堆,拿走至少一个石子,但不能拿走超过一半的石子. 谁不能拿石子就算输,问先手胜负情况 n<=100,1<=a[i]< ...
- UVA1482 Playing With Stones —— SG博弈
题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一 ...
随机推荐
- SPOJ1026 概率DP
Favorite Dice BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorit ...
- 006---Django静态文件配置
静态文件:Js.Css.Fonts.Image等 这个不难.在setting.py文件加一行 # 别名 用户在url地址栏输入127.0.0.1:8000/static/文件 可以直接访问static ...
- [Hdu4825]Xor Sum(01字典树)
Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问 ...
- Eclipse 创建 XML 文件---Eclipse教程第12课
打开新建 XML 文件向导 你可以使用新建 XML 文件向导来创建 XML 文件.打开向导的方式有: 点击 File 菜单并选择 New > Other 点击新建下拉框 () 选择 Other ...
- 有关ViewPager的使用及解决Android下ViewPager和PagerAdapter中调用notifyDataSetChanged失效的问题
ViewPager是android-support-v4.jar包中的一个系统控件,继承自ViewGroup,专门用以实现左右滑动切换View的效果,使用时需要首先在Project->prope ...
- 《Cracking the Coding Interview》——第16章:线程与锁——题目3
2014-04-27 19:26 题目:哲学家吃饭问题,死锁问题经典模型(专门用来黑哲学家的?). 解法:死锁四条件:1. 资源互斥.2. 请求保持.3. 非抢占.4. 循环等待.所以,某砖家拿起一只 ...
- USACO Section1.4 Arithmetic Progressions 解题报告
ariprog解题报告 —— icedream61 博客园(转载请注明出处)-------------------------------------------------------------- ...
- 23、php知识点总结基础教程--part-1
1.基本语法 PHP 脚本可放置于文档中的任何位置. PHP 脚本以 <?php 开头,以 ?> 结尾 <?php // 此处是 PHP 代码 ?> PHP 文件的默认文件扩展 ...
- 【Minimum Window】cpp
题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...
- spring 笔记2:Spring MVC : Did not find handler method for 问题的解决
日志显示为: Looking up handler method for path /***Did not find handler method for [/***]No mapping found ...