HDU3537-Daizhenyang's Coin(博弈SG-打表)
<span style="color: green; font-family: Arial; font-size: 12px; background-color: rgb(255, 255, 255);">Daizhenyang's Coin
</span>
<span style="color: green; font-family: Arial; font-size: 12px; background-color: rgb(255, 255, 255);">Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)</span>
</span>
Total Submission(s): 320 Accepted Submission(s): 146
to the girl that he's better and more intelligent than any other chaser. So he arranged a simple game: Coin Flip Game. He invited the girl to be the judge.
In this game, n coins are set in a row, where n is smaller than 10^8. They took turns to flip coins, to flip one coin from head-up to tail-up or the other way around. Each turn, one can choose 1, 2 or 3 coins to flip, but the rightmost selected must be head-up
before flipping operation. If one cannot make such a flip, he lost.
As we all know, Daizhenyang is a very smart guy (He's famous for his 26 problems and Graph Theory Unified Theory-Network Flow does it all ). So he will always choose the optimal strategy to win the game. And it's a very very bad news for all the competitors.
But the girl did not want to see that happen so easily, because she's not sure about her feelings towards him. So she wants to make Daizhenyang lose this game. She knows Daizhenyang will be the first to play the game. Your task is to help her determine whether
her arrangement is a losable situation for Daizhenyang.
For simplicity, you are only told the position of head-up coins. And due to the girl's complicated emotions, the same coin may be described twice or more times. The other coins are tail-up, of course.
Coins are numbered from left to right, beginning with 0.
0
1
0
4
0 1 2 3
Yes
No
Yes翻硬币的经典例子-MOCK-TURTLES打表发现:x: 0 1 2 3 4 5 6 7...g(x): 1 2 4 7 8 11 13 14...发现x化作2进制1的个数为奇数时。g(x)= 2*x 否则 g(x) = 2*x+1 SG和即是答案。#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int n;
set<int>st;
int main(){ while(~scanf("%d",&n)){
int ans = 0;
st.clear();
for(int i = 0; i < n; i++){
int t;
scanf("%d",&t);
if(st.count(t)==0){
if(t==0) ans ^= 1;
else{
int k = t,cnt = 0;
while(k){
k = k&(k-1);
cnt++;
}
if(cnt%2==0) ans ^= (2*t+1);
else ans ^= 2*t; }
st.insert(t);
} }
if(ans==0){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
}
return 0;
}
HDU3537-Daizhenyang's Coin(博弈SG-打表)的更多相关文章
- 51nod_1714:B君的游戏(博弈 sg打表)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #incl ...
- 51nod 1714:B君的游戏(博弈 sg打表)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #incl ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- HDU 3032 (SG打表找规律)
题意: 有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围 ...
- 博弈SG
先转一篇看得比较懂的,以后有时间自己再归纳下 转自:http://blog.csdn.net/logic_nut/article/details/4711489 博弈问题若你想仔细学习博弈论,我强烈推 ...
- BZOJ-1228 E&D 博弈SG+找啊找啊找规律
讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...
- hdu 3032(博弈sg函数)
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办 ...
- HDU-4678 Mine 博弈SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4678 题意就不说了,太长了... 这个应该算简单博弈吧.先求联通分量,把空白区域边上的数字个数全部求出 ...
随机推荐
- Kendo UI开发教程(22): Kendo MVVM 数据绑定(十一) Value
Value绑定可以把ViewModel的某个属性绑定到DOM元素或某个UI组件的Value属性.当用户修改DOM元素或UI组件的值时,绑定的ViewModel的值也随之发生改名.同样,如果ViewMo ...
- 第五天学习内容 for循环,嵌套
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 在JDBC中使用PreparedStatement代替Statement,同时预防SQL注入
本篇讲诉为何在JDBC操作数据库的过程中,要使用PreparedStatement对象来代替Statement对象. 在前面的JDBC学习中,对于Statement对象,我们已经知道是封装SQL语句并 ...
- Android SDK 环境变量配置(Windows)
Android 开发需要进行adb的配置, 这里使用的是 adt-bundle-windows-x86_64-20140321, 里面捆绑的有 eclipse ,不需要再进行 其他的配置,直接下载解压 ...
- javascript 自己主动绑定JS callback 的方法函数
自己写的一个javascript 智能绑定callback 而且调用运行的函数.主要用于异步请求的 ajax中: <!DOCTYPE html> <html> <head ...
- android平台中,EventBus研究学习
当一个Android应用功能越来越多的时候.app中各个部分之间通信.往往採用Observer的方式来进行,即注冊----通知----注销的方式运行 各类控件常常须要依据某个状态来更 ...
- 全局忽略编译警告(设置QMAKE_CXXFLAGS )
msvc编译器从2010 sp1开始就已经支持UTF-8的源码文件了,然后到vs2012又不支持了,官方表示是BUG.到目前最新的vs2013就解决了这个问题... 但是在编译时仍然会出现4819的警 ...
- 将Datagridview中的数据导出至Excel中
首先添加一个模块ImportToExcel,并添加引用 然后导入命名空间: Imports Microsoft.Office.Interop Imports System.Da ...
- 在toolbar里动态创建多个button(ext.net)
private void setOneMenu() { string sql = "select id,name,gids from Config where name<>'高级 ...
- VS2012配置astyle格式化代码
1.工具->扩展和更新,搜astyle插件,下载安装重启,当前是2.0版本. 2.工具->选项->AStyle Formatter->Edit,填入下面的,点击save,确定. ...