Industrial Nim
http://codeforces.com/contest/15/problem/C
题意:
现有n个采石场,第i个采石场有mi堆石子
各堆分别有xi,xi+1……,xi+m-1颗石子
两名选手使用最优策略进行Nim游戏,双方轮流操作
每次操作为从任意一堆石子取出任意数量的石子,不能操作者败
现对于一初始局面,先手必胜输出“tolik”,否则输出“bolik”(不含引号)
解法:
显然核心算法仍然是Nim
然后用脑子想想
f(x)表示1-x的异或和怎么求就好了
其实怎么求都可以,想清楚就好了
#include <cstdio>
#include <iostream> using namespace std; typedef long long ll; ll f(ll x) {
ll res = , cnt;
for(ll i = ;i <= x;i <<= ) {
cnt = x / (i << ) * i;
if(x % (i << ) >= i) cnt += x % (i << ) - i + ;
if(cnt & ) res |= i;
}
return res;
} int main() {
int t;
ll m, x, ans = ;
cin >> t;
while(t --) {
cin >> x >> m;
ans ^= f(m + x - ) ^ f(x - );
}
puts(ans ? "tolik" : "bolik");
return ;
}
Industrial Nim的更多相关文章
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- codeforces 15C. Industrial Nim
题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...
- [CF15C]Industrial Nim
题目大意:有$n$个采石场,每行一个$m_i$一个$x_i$,表示第$i$个采石场有$m_i$辆车,这个采石场中车中的石子为从$x_i$开始的自然数.Nim游戏若先手赢输出"tolik&qu ...
- Codeforces 15C Industrial Nim 简单的游戏
主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...
- [LeetCode] Nim Game 尼姆游戏
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- LeetCode 292. Nim Game
Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...
- 【SRM】518 Nim
题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...
随机推荐
- java使用poi读取doc和docx文件(maven自动导入依赖包)
java使用poi读取doc和docx文件(maven自动导入依赖包) 于是在网上搜寻了一阵之后才发现原来doc文档和excel一样不能用普通的io流的方法来读取,而是也需要用poi,于是进行了一番尝 ...
- B. Trees in a Row(cf)
B. Trees in a Row time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- yii登陆中添加验证码
1.在SiteController中添加如下代码: /** * Declares class-based actions. */ public function actions() { return ...
- [Swift通天遁地]三、手势与图表-(9)制作五彩缤纷的气泡图表
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]七、数据与安全-(15)使用单元测试进行代码的性能分析
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- akka设计模式系列-Chain模式
链式调用在很多框架和系统中经常存在,算不得上是我自己总结的设计模式,此处只是简单介绍在Akka中的两种实现方式.我在这边博客中简化了链式调用的场景,简化后也更符合Akka的设计哲学. trait Ch ...
- akka设计模式系列-基础模式
本文介绍akka的基本使用方法,由于属于基础功能,想不出一个很高大上的名称,此处就以基础模式命名.下文会介绍actor的使用方法,及其优劣点. class SimpleActor(name:Strin ...
- UNIX环境高级编程--2
UNIX标准及实现 ISO C: 国际标准化组织(International Organization for standardization , ISO)ISO C标准的意图是提供C程序的可移植性, ...
- 10 在C#中读取文件
我们在前一个练习中已经了解了如何在C#控制台程序(console)中读取用户的输入.现在我们要学习如何从一个文件中读取内容.在下面的练习中,你要格外小心.关于文件的操作,一不小心会损失你的重要文件. ...
- 函数 out 传值 分割
public void Jia(int a ,int b) { a = a + b; Console.WriteLine(a); } public void Jia1(int a,out int b) ...