Codeforces 15C 博弈

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 hasxi + 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
2
2 1
3 2
output
tolik
input
4
1 1
1 1
1 1
1 1
output
bolik


题意:现有n个采石场,第i个采石场有mi堆石子,各堆分别有xi,xi+1……,xi+m-1颗石子。两名选手使用最优策略进行Nim游戏,双方轮流操作,每次操作为从任意一堆石子取出任意数量的石子,不能操作者败。现对于一初始局面,先手必胜输出“tolik”,否则输出“bolik”(不含引号)。


题解:简单尼姆博弈  x^(x+1)^...^(x+m-1)=f(x-1)^f(x+m-1)

f(n)=1^2^3^...^n

按位算f(n)即可


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll f(ll t){
	ll now=0,ts=1,ans=0;
	ll d=t%4;
	if(d==1||d==2)ans=1;
	ts=2;
	while(ts<=t){
		now=0;
		ll d=t-ts+1;
		d=d%(ts*2);
		if(d<=ts&&d%2)now=1;
		ans+=now*ts;
		ts*=2;
	}
	return ans;
}
int main(){
	ll i,j,n,x,k,now=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&x,&k);
		now^=f(x-1)^f(x+k-1);
	}
	if(now)printf("tolik\n");
	else printf("bolik\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值