CodeForces 15C Industrial Nim
来源:互联网 发布:java 图形界面案例 编辑:程序博客网 时间:2024/06/05 22:30
Description
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.
Sample Input
22 13 2
tolik
41 11 11 11 1
bolik
nim取子游戏,异或和为0即为先手必败,其余为先手必胜,然后问题转换为求l到r的异或和,再转化为求1到n的异或和。打表找找规律可以知道只有四种情况。
#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<cmath>#include<vector>#include<string>#include<queue>#include<map>#include<algorithm>using namespace std;#define LL __int64int T;LL get(LL x){ if ((x&3)==0) return x;if ((x&3)==1) return 1;if ((x&3)==2) return x+1;if ((x&3)==3) return 0;}int main(){ while (~scanf("%d",&T)){LL ans=0,x,y;while(T--){scanf("%I64d%I64d",&x,&y);ans^=get(x-1)^get(x+y-1);}if (ans) printf("tolik\n");else printf("bolik\n");} return 0;}
- Codeforces 15C Industrial Nim
- CodeForces 15C. Industrial Nim
- Codeforces-15C Industrial Nim
- CodeForces 15C Industrial Nim
- CodeForces 15C Industrial Nim
- CodeForces 15C Industrial Nim
- codeforces 15C Industrial Nim(NIM 博弈)
- CodeForces 15C Industrial Nim (博弈)
- Codeforces 15C Industrial Nim 简单博弈
- Codeforces Beta Round #15-C. Industrial Nim
- CodeForces 15C Industiral Nim Nim游戏
- 11月1日个人训练赛C - Industrial Nim
- CF15C Industrial Nim
- NIM游戏-博弈论(poj2975+CodeForces
- ROS-Industrial
- CodeForces Round #417 E Solution:Nim博弈
- 292. Nim Game (C++)
- nim
- 深度探索C++对象模型(3)
- CodeForces 15A Elephant
- 【HDU5656】CA Loves GCD——动态规划
- J2EE中Servlet实现的三种方法
- Java NIO - volatile
- CodeForces 15C Industrial Nim
- LeetCodet题解--12. Integer to Roman
- CodeForces 560CGerald's Hexagon(几何)
- 三言两语说shader(六)外发光、表面shader
- JavaWeb - 知识点
- 第六周项目三 IP地址类
- [BZOJ1067][SCOI2007]降雨量(线段树)
- ZOJ 2836Number Puzzle(容斥原理)
- Tsinsen A1106 数制转换