C. Industrial Nim
time limit per test

2 seconds

memory limit per test

64 megabytes

input

standard input

output

standard output

There are n stone quarries in Petrograd.

Each quarry owns mi dumpers (1 ≤ i ≤ n). It is known that the first dumper of the i-th quarry has xi stones in it, the second dumper has xi + 1 stones in it, the third has xi + 2, and the mi-th dumper (the last for the i-th quarry) has xi + mi - 1 stones in it.

Two oligarchs play a well-known game Nim. Players take turns removing stones from dumpers. On each turn, a player can select any dumper and remove any non-zero amount of stones from it. The player who cannot take a stone loses.

Your task is to find out which oligarch will win, provided that both of them play optimally. The oligarchs asked you not to reveal their names. So, let's call the one who takes the first stone «tolik» and the other one «bolik».

Input

The first line of the input contains one integer number n (1 ≤ n ≤ 105) — the amount of quarries. Then there follow n lines, each of them contains two space-separated integers xi and mi (1 ≤ xi, mi ≤ 1016) — the amount of stones in the first dumper of the i-th quarry and the number of dumpers at the i-th quarry.

Output

Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.

Examples
Input

Copy
2
2 1
3 2
Output
tolik
Input

Copy
4
1 1
1 1
1 1
1 1
Output
bolik

这题是变形的尼姆博弈,知道什么是尼姆博弈的话,难点就在于位运算了。看到一篇博客的代码写的很详细。

附ac代码(有注释):
 1 #include <iostream>
2 #include <cstdio>
3 using namespace std;
4
5 typedef long long LL;
6 LL get(LL x,LL m) //n^(n+1)=1(n为偶数) 1^1=0 0^0=0
7 {
8 LL ans;
9 if(m&1){
10 if(x&1)
11 ans=x;//后面的可以配成对
12 else
13 ans=x+m-1;//除去最后一项前面的可以配成对
14 m--;
15 }
16 else{
17 if(x&1){
18 ans=x^(x+m-1);//中间的可以配成对
19 m-=2;
20 }
21 else
22 ans=0;
23 }
24 if(m%4)//判断是否为偶数对
25 return ans^1;
26 else
27 return ans;
28 }
29 int main()
30 {
31 int n;
32 long long a,b;
33 while(~scanf("%d",&n)){
34 long long ans=0;
35 for(int i=0;i<n;i++){
36 scanf("%lld%lld",&a,&b);
37 ans^=get(a,b);
38 }
39 if(ans)
40 puts("tolik");
41 else
42 puts("bolik");
43 }
44 return 0;
45 }

博客地址:http://blog.csdn.net/bigbigship/article/details/31031815

codeforces - 15C Industrial Nim(位运算+尼姆博弈)的更多相关文章

  1. Nim游戏(尼姆博弈)

    这里是尼姆博弈的模板,前面的博弈问题的博客里也有,这里单列出来. 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜.假设A B都非 ...

  2. codeforces 15C. Industrial Nim

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

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

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

  4. 51Nod 1069:Nim游戏(尼姆博弈)

    1069 Nim游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 有N堆石子.A B两个人轮流拿,A先拿.每次只能从一堆中取若干个,可将一堆全取走, ...

  5. Light OJ 1253 Misere Nim (尼姆博弈(2))

    LightOJ1253 :Misere Nim 时间限制:1000MS    内存限制:32768KByte   64位IO格式:%lld & %llu 描述 Alice and Bob ar ...

  6. codeforces 812 E. Sagheer and Apple Tree(树+尼姆博弈)

    题目链接:http://codeforces.com/contest/812/problem/E 题意:有一颗苹果树,这个苹果树所有叶子节点的深度要不全是奇数,要不全是偶数,并且包括根在内的所有节点上 ...

  7. POJ 2975 Nim 尼姆博弈

    题目大意:尼姆博弈,求先手必胜的情况数 题目思路:判断 ans=(a[1]^a[2]--^a[n]),求ans^a[i] < a[i]的个数. #include<iostream> ...

  8. POJ2975 Nim 博弈论 尼姆博弈

    http://poj.org/problem?id=2975 题目始终是ac的最大阻碍. 问只取一堆有多少方案可以使当前局面为先手必败. 显然由尼姆博弈的性质可以知道需要取石子使所有堆石子数异或和为0 ...

  9. 尼姆博弈(Nimm's Game)

    题型: 有3堆各若干个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取1个,多者不限,最后取光者得胜. 思路 首先自己想一下,就会发现只要最后剩两堆物品一样多(不为零),第三堆为零,那面对这种局 ...

随机推荐

  1. VMware下安装Ubantu 18.04

    一.VIM安装及配置 1.安装VIM sudo apt-get install vim 二.拼音输入法以及搜狗拼音输入法安装 1.安装Fcitx输入框架 sudo apt-get install fc ...

  2. 处理 K8S Orphaned pod found - but volume paths are still present on disk 孤儿pod

    问题概述 查看kubelet或/var/log/messages日志一直包错,发现是孤儿pod,是由于其pod被删除后存储路径还保存在磁盘. 报错如下 [root@node5 ~]# journalc ...

  3. JMeter去掉启动的cmd命令窗口和制作快捷方式

    1.去掉启动的cmd命令窗口 在使用jmeter时,如果使用默认的jmeter.bat启动的话,会出现一个CMD命令窗口,之后才会启动jmeter工作界面: 如果直接启用ApacheJMeter.ja ...

  4. centos 7.0 ping百度提示:ping: www.baidu.com: Name or service not known

    解决方法一: 添加dns服务器 vi /etc/resolv.conf 在文件中添加如下两行: nameserver 8.8.8.8 nameserver 8.8.4.4 保存退出,重启服务器.之后再 ...

  5. Shell从入门到精通

    熟悉基本shell操作不仅是运维的基本功,对于开发来说也是多多益善,我在学习的过程中,总结了十个练手的小demo,并附上涉及的知识点,仅供娱乐. 1. 多线程ping监控,检查同一网段的IP是否连通 ...

  6. Mybatis SQL映射文件详解

    Mybatis SQL映射文件详解 mybatis除了有全局配置文件,还有映射文件,在映射文件中可以编写以下的顶级元素标签: cache – 该命名空间的缓存配置. cache-ref – 引用其它命 ...

  7. VMwareWorkstation 平台 Ubuntu14 下安装配置 伪分布式 hadoop

    VMwareWorkstation平台Ubuntu14下安装配置伪分布式hadoop 安装VmwareStation 内含注册机. 链接:https://pan.baidu.com/s/1j-vKgD ...

  8. jemeter断言和性能分析

    一.添加断言 1.原因:检查是否有该结果,一般一个请求过去除了400和500的只要通过的都会代表请求成功,比如登录页面及时填写了错误密码,虽然会返回密码错误,但这个请求还是成功的,所以我们要添加断言, ...

  9. token的分层图如下

    基于 token 的多平台身份认证架构设

  10. pywin32 pywin32 docx文档转html页面 word doc docx 提取文字 图片 html 结构

    https://blog.csdn.net/X21214054/article/details/78873338# python docx文档转html页面 - 程序猿tx - 博客园 https:/ ...