Question link: Click the open link
Question:
Given n
Below n rows, each line 2 u v represents a V heap Stone: u, u + 1, U + 2 · u + V-1
Ask if the first hand wins or the second hand wins
Ideas:
First, based on the game conclusion of Nim
Returns 0 or a non-zero number.
Here, we want to optimize it because there are too many numbers.
In fact, for a sequence of u, u + 1, U + 2 ····
Obviously, the difference or result of two groups, {} {, 6, 7}, and {8, 9}, is 1.
You only need to group the sequence into {even, odd}
Then, Run "Y ..
#include<stdio.h>#include<iostream>#include<string.h>#include<set>#include<vector>#include<map>#include<math.h>#include<string>#include<stdlib.h>#include<algorithm>using namespace std;#define N 123456#define ll __int64ll n;ll a[N],b[N];int main(){ll i,j;while(cin>>n){ll ans = 0;for(i=1;i<=n;i++) {cin>>a[i]>>b[i];ll endd = a[i]+b[i]-1;if(a[i]&1) {ans ^= a[i];a[i]++, b[i]--;}if(b[i]) {ll siz = b[i]>>1;if(siz&1)ans^=1;if(b[i]&1)ans^=endd;}}ans?puts("tolik"):puts("bolik");}return 0;}