uva1482:Playing With Stones (SG函数)
题意:有N堆石子,每次可以取一堆的不超过半数的石子,没有可取的为输。
思路:假设只有一堆,手推出来,数量x可以表示为2^p-1形式的必输。 但是没什么用,因为最后要的不是0和1,而是SG函数;所以必输的为0,那么其他的呢?
我们可以发现SG=0的位置是1,3,7,15,31....
SG=1, 2,5,11,23....
可以推出来,也可以打表。
(水题,这题可以放这里以后讲课用。
sg[]=;
for(int i=;i<=;i++){
memset(vis,,sizeof(vis));
for(int j=;j<=i/;j++) vis[sg[i-j]]=;
for(int j=;;j++){
if(!vis[j]) {sg[i]=j; break;}
}
}
for(int i=;i<=;i++) cout<<i<<" "<<sg[i]<<endl;
完整代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll SG(ll x){
if(x&1LL) return SG(x/);
return x/;
}
int main()
{
int T,N,ans; ll x,q;
scanf("%d",&T);
while(T--){
ans=; scanf("%d",&N);
for(int i=;i<=N;i++){
scanf("%lld",&x);
ans^=SG(x);
}
if(ans) puts("YES");
else puts("NO");
}
return ;
}
uva1482:Playing With Stones (SG函数)的更多相关文章
- UVA1482 Playing With Stones —— SG博弈
题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一 ...
- UVA 1482 - Playing With Stones(SG打表规律)
UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...
- LA 5059 (找规律 SG函数) Playing With Stones
题意: 有n堆石子,两个人轮流取,每次只能取一堆的至少一个至多一半石子,直到不能取为止. 判断先手是否必胜. 分析: 本题的关键就是求SG函数,可是直接分析又不太好分析,于是乎找规律. 经过一番“巧妙 ...
- UVALive 5059 C - Playing With Stones 博弈论Sg函数
C - Playing With Stones Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu S ...
- 【LA5059】Playing With Stones (SG函数)
题意:有n堆石子,分别有a[i]个.两个游戏者轮流操作,每次可以选一堆,拿走至少一个石子,但不能拿走超过一半的石子. 谁不能拿石子就算输,问先手胜负情况 n<=100,1<=a[i]< ...
- Light OJ 1296 - Again Stone Game (博弈sg函数递推)
F - Again Stone Game Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- hdu1536&&hdu3023 SG函数模板及其运用
S-Nim Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status ...
- HDU 1536 sg函数
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Light OJ 1199 - Partitioning Game (博弈sg函数)
D - Partitioning Game Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
随机推荐
- 字符集(编码)转换_Linux
ZC: 来自 我的项目 czgj 1.代码: #include <stdio.h> #include <iconv.h> #include <string.h> / ...
- string_01
内存释放和越界 越界:(1).复制越界,(2).取值越界 构造函数 (1).默认 空(无参) (2).拷贝(const string &) (3).带参数: const char * // Z ...
- Android中getLocationOnScreen和getLocationInWindow 获取屏幕大小
需要确定组件在父窗体中的坐标时,使用getLocationInWindow,需要获得组件在整个屏幕的坐标时,使用getLocationOnScreen. 其中location [0]代表x坐标,loc ...
- 使用cocos创建的项目,如何进行源码调试?
环境cocos3.10,里面包含了cocos2dx 3.10引擎.但是用cocos创建出来的项目,使用的lib和dll是文件夹Cocos\Cocos2d-x\cocos2d-x-3.10\prebui ...
- 算法笔记--字符串hash
概述: 主要用于字符串的匹配. 定义hash函数: H(c)=(c1bm-1 +c2bm-2 +...+cmb0)mod h 对于字符串c中l-r区间的hash值: H(l,r)=H(1,r)-H(1 ...
- (转)HapMap简介
1.人类基因组的HapMap和国际HapMap计划 (1)何谓HapMap HapMap是Haplotype Map 的简称,Haplo意为单一,在基因组中专指来自父母的一对染色体中的一条.Haplo ...
- English trip V1 - 辅导课 VOCABULARY BRUSH UP(1-6) 词汇刷新 SA:Winona
1.How Do you Feel Now? 形容词 adj. = adjective Describe people and thi ...
- Linux : 密码正确不能正常登陆,日志提示Could not get shadow information for user
今天,再玩Centos7的时候,尝试修改了下ssh的端口.因为默认开启了SELinux,如果没有修改这个文件配置就修改端口sshd服务就不能正常启动了. 但是,当我修改会22端口的时候还是不能正常登陆 ...
- Error when clicking other button after displaying Popup window(转)
原文地址:Error when clicking other button after displaying Popup window Hi, I'm developing a custom page ...
- Intel DAAL AI加速——神经网络
# file: neural_net_dense_batch.py #================================================================= ...