Skip to content

Commit a810f74

Browse files
committed
Industrial Nim is added
1 parent b1977a2 commit a810f74

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Industrial Nim/Industrial_Nim.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<long long> vec;
5+
bool nim() /* return true if the first player will win */
6+
{
7+
long long x=0;
8+
for(int i=0;i<vec.size();i++) x=x^vec[i];
9+
return x>0;
10+
}
11+
12+
long long f(long long n) /* n&3 equivalent to n%4 */
13+
{
14+
long long x=n&3;
15+
if(x==0) return n; if(x==1) return 1;
16+
if(x==2) return n+1; if(x==3) return 0;
17+
}
18+
19+
20+
21+
int main()
22+
{
23+
long long n,x,m;
24+
cin>>n;
25+
while(n--)
26+
{
27+
cin>>x>>m;
28+
vec.push_back(f(x+m-1)^f(x-1));
29+
}
30+
if(nim())
31+
cout<<"tolik"<<endl;
32+
else
33+
cout<<"bolik"<<endl;
34+
}
35+

Industrial Nim/Industrial_Nim.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Statement:
2+
There are n stone quarries in Petrograd.
3+
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.
4+
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.
5+
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».
6+
7+
Input:
8+
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.
9+
10+
Output:
11+
Output «tolik» if the oligarch who takes a stone first wins, and «bolik» otherwise.
12+
13+
Example1
14+
input:
15+
2
16+
2 1
17+
3 2
18+
output:
19+
tolik
20+
21+
Example2
22+
input:
23+
4
24+
1 1
25+
1 1
26+
1 1
27+
1 1
28+
output:
29+
bolik

0 commit comments

Comments
 (0)