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. openshift 3.11安装部署

    openshift 3.11 安装部署 openshift安装部署 1 环境准备(所有节点) openshift 版本 v3.11 1.1 机器环境 ip cpu mem hostname OSsys ...

  2. Java并发包源码学习系列:JDK1.8的ConcurrentHashMap源码解析

    目录 为什么要使用ConcurrentHashMap? ConcurrentHashMap的结构特点 Java8之前 Java8之后 基本常量 重要成员变量 构造方法 tableSizeFor put ...

  3. 获取网页url中的参数

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 简易双色球dome分享

    代码如下: <style type="text/css"> div {font-weight: bold;text-align: center;} .tone{widt ...

  5. 自动化接口差异测试-diffy 回归测试 charles rewrite 请求

    https://mp.weixin.qq.com/s/vIxbtQtRRqgYCrDy7XTcrA 自动化接口差异测试-diffy Boris 搜狗测试 2018-08-30   自动化接口差异测试- ...

  6. 字节跳动在 Go 网络库上的实践

    https://mp.weixin.qq.com/s/wSaJYg-HqnYY4SdLA2Zzaw RPC 框架作为研发体系中重要的一环,承载了几乎所有的服务流量.本文将简单介绍字节跳动自研网络库 n ...

  7. 唯一ID生成算法剖析

    https://mp.weixin.qq.com/s/E3PGP6FDBFUcghYfpe6vsg 唯一ID生成算法剖析 原创 cloudoxou 腾讯技术工程 2019-10-08    

  8. 在VMware15安装Ubuntu 16.04

    安装环境: VMware15 VMware15官网地址:https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_computing ...

  9. MarkDown学习笔记 Typora

    快捷方式篇 新建 ctrl + N 新建窗口 ctrl + shift + N 打开md文件 ctrl + O 快速打开 ctrl + P 保存 ctrl + S 另存为 ctrl + shift + ...

  10. Docker综述

    Docker综述 1.Docker是干什么的? 2.Docker的核心:镜像.容器.仓库 2.1 容器与虚拟机的区别 2.2 仓库 Docker作用 3.Docker的使用 1.Docker是干什么的 ...