Codeforces Beta Round #15-C. Industrial Nim

来源:互联网 发布:阿里云是什么 编辑:程序博客网 时间:2024/06/05 15:19

原题链接

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
22 13 2
output
tolik
input
41 11 11 11 1
output
bolik


求出每个dumper中的石头数进行异或,

对于x, x+1, x+2,...x+m进行异或,经过观察发现, a, a+1若a是偶数那么a^a+1必定为1,所以可以利用这个性质进行运算

#include <cstdio>#include <iostream>#define maxn 1005 #define MOD 1000000007typedef long long ll;using namespace std;int main(){//freopen("in.txt", "r", stdin);ll x, m, ans = 0;int n;scanf("%d", &n);while(n--){scanf("%I64d%I64d", &x, &m);if(x&1){ans ^= x;ll h = m - 1;    h /= 2;    if(h&1)     ans ^= 1;    if((m - 1) % 2)     ans ^= x + m - 1;}else{ll h = m / 2;if(h&1) ans ^= 1;if(m % 2) ans ^= x + m - 1;}}if(ans) puts("tolik");else puts("bolik");return 0;} 


0 0
原创粉丝点击