题目大意:有$n$个采石场,每行一个$m_i$一个$x_i$,表示第$i$个采石场有$m_i$辆车,这个采石场中车中的石子为从$x_i$开始的自然数。Nim游戏若先手赢输出"tolik",后手赢输出"bolik"。

题解:Nim游戏,可以发现连续的四个自然数且第一个数可被4整除,那么它们的异或值为0

卡点:1.未考虑$m_i < 4$的情况

  2.未考虑$x_i < 4$的情况

C++ Code:

#include <cstdio>
#define int long long
using namespace std;
int n, x, m, ans;
inline int min(int a, int b) {return a < b ? a : b;}
int calc(int x) {
int tmp = x % 4;
if (!tmp) return x;
else if (tmp == 1) return 1;
else if (tmp == 2) return x + 1;
else if (tmp == 3) return 0;
}
int run(int x, int m) {
return calc(x - 1) ^ calc(x + m - 1);
}
//int run(int x, int m) {
// int tmp = (x - 1) / 4 + 1, res = 0;
// for (int i = x; i < min(x + m, tmp * 4); i++) res ^= i;
// tmp = (x + m - 1) / 4;
// for (int i = tmp * 4; i <= x + m - 1; i++) res ^= i;
// return res;
//}
signed main() {
scanf("%lld", &n);
while (n--) {
scanf("%lld%lld", &x, &m);
ans ^= run(x, m);
}
if (ans) puts("tolik");
else puts("bolik");
return 0;
}

  

[CF15C]Industrial Nim的更多相关文章

  1. codeforces - 15C Industrial Nim(位运算+尼姆博弈)

    C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...

  2. codeforces 15C. Industrial Nim

    题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...

  3. Industrial Nim

    http://codeforces.com/contest/15/problem/C 题意: 现有n个采石场,第i个采石场有mi堆石子 各堆分别有xi,xi+1……,xi+m-1颗石子 两名选手使用最 ...

  4. Codeforces 15C Industrial Nim 简单的游戏

    主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...

  5. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  8. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  9. 【SRM】518 Nim

    题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...

随机推荐

  1. angularjs 自定义服务(serive,factory,provder) 以及三者的区别

    1.Serive 服务:通过service方式创建自定义服务,相当于new的一个对象:var s = new myService();,只要把属性和方法添加到this上才可以在controller里调 ...

  2. Yaf学习(二)----Yaf初体验

    1.hello world 1.1 用yaf输出hello world 1.首先配置host,nginx 2.host不用多说,指向虚拟机IP即可 1.2 重点说一下nginx (只说server块) ...

  3. JNI模板

    java为了调用底层驱动函数,需要调用外部的C/C++代码,java提供了JNI接口: 然后将C代码编译成库(windows下 .dll / android环境下 .so) arm-linux-gcc ...

  4. python中如何统计一个类的实例化对象

    类中的静态变量 需要通过类名.静态变量名 来修改 :通过对象不能修改 python中如何统计一个类的实例化对象?? class Person: #静态变量count,用于记录类被实例化的次数 coun ...

  5. labview初始学习过程中遇到串口读取框红蓝色交替闪烁的处理

           labview工程的程序框图VISA串口读取框红蓝交替闪烁,前面板接收数据错乱,或者是接受不了,这是你不小心设置了断点.

  6. Hibernate-ORM:07.Hibernate中的参数绑定

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客会讲解Hibernate中的参数绑定,就是相当于sql语句中的where后面的条件 一,讲解概述: 1 ...

  7. web框架与爬虫

    所有的web框架 http://www.cnblogs.com/wupeiqi/articles/5341480.html 爬虫技术 http://www.cnblogs.com/wupeiqi/ar ...

  8. SharePoint显示错误信息

         在SharePoint项目中,一般如果发生错误,SharePoint会弹出它自定义的报错页面,一般就显示"Something went wrong",如果光是看这一句话, ...

  9. html5判断设备的动作

    相应的事件 deviceorientation事件提供设备的物理方向信息,表示为一系列本地坐标系的旋角. devicemotion事件提供设备的加速信息,表示为定义在设备上的坐标系中的卡尔迪坐标.其还 ...

  10. Ubuntu下使用Git_3

    这里是我举得小白阶段比较困难的地方了, 当在我们向远程数据库推送数据之前,有其他用户向远程数据库推送的相同的文件的时候,服务器会拒绝我们的推送,这个时候就需要我们来整合这两个文件 如图说是,现在显示的 ...