[CF15C]Industrial Nim
题目大意:有$n$个采石场,每行一个$m_i$一个$x_i$,表示第$i$个采石场有$m_i$辆车,这个采石场中车中的石子为从$x_i$开始的自然数。Nim游戏若先手赢输出"tolik",后手赢输出"bolik"。
题解:Nim游戏,可以发现连续的四个自然数且第一个数可被4整除,那么它们的异或值为0
卡点:1.未考虑$m_i < 4$的情况
2.未考虑$x_i < 4$的情况
C++ Code:
#include <cstdio>
#define int long long
using namespace std;
int n, x, m, ans;
inline int min(int a, int b) {return a < b ? a : b;}
int calc(int x) {
int tmp = x % 4;
if (!tmp) return x;
else if (tmp == 1) return 1;
else if (tmp == 2) return x + 1;
else if (tmp == 3) return 0;
}
int run(int x, int m) {
return calc(x - 1) ^ calc(x + m - 1);
}
//int run(int x, int m) {
// int tmp = (x - 1) / 4 + 1, res = 0;
// for (int i = x; i < min(x + m, tmp * 4); i++) res ^= i;
// tmp = (x + m - 1) / 4;
// for (int i = tmp * 4; i <= x + m - 1; i++) res ^= i;
// return res;
//}
signed main() {
scanf("%lld", &n);
while (n--) {
scanf("%lld%lld", &x, &m);
ans ^= run(x, m);
}
if (ans) puts("tolik");
else puts("bolik");
return 0;
}
[CF15C]Industrial Nim的更多相关文章
- codeforces - 15C Industrial Nim(位运算+尼姆博弈)
C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- codeforces 15C. Industrial Nim
题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...
- Industrial Nim
http://codeforces.com/contest/15/problem/C 题意: 现有n个采石场,第i个采石场有mi堆石子 各堆分别有xi,xi+1……,xi+m-1颗石子 两名选手使用最 ...
- Codeforces 15C Industrial Nim 简单的游戏
主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...
- [LeetCode] Nim Game 尼姆游戏
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- LeetCode 292. Nim Game
Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...
- 【SRM】518 Nim
题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...
随机推荐
- p标签内不能含有块元素。
原来一直听网上这样说.自己并没有实际遇到过.上例子. <!DOCTYPE html> <html> <head> <meta charset="ut ...
- 监听浏览器返回,pushState,popstate 事件,window.history对象
在WebApp或浏览器中,会有点击返回.后退.上一页等按钮实现自己的关闭页面.调整到指定页面.确认离开页面或执行一些其它操作的需求.可以使用 popstate 事件进行监听返回.后退.上一页操作. 一 ...
- Java处理中文乱码问题
package servlet; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.ser ...
- 双击 ajax修改单元格里的值
最终效果 列表页面表格里双击排序修改其值 按钮样式要引入bootstrap才可以用 本文件用的是laravel框架环境 larave路由里 Route::get('category/changesta ...
- 人人都会设计模式:观察者模式--Observer
https://segmentfault.com/a/1190000012295887 观察者模式是抽像通知者和观察者,达到具体通知者跟具体观察者没有偶合.能达到不管是切换通知者,或者是切换观察者,都 ...
- python2.7入门---循环语句(for&嵌套循环)
咱们直接先来看for循环.Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串.然后再来看一下它的语法结构: for iterating_var in sequence: ...
- set<pair<int,int> > 的运用
In this cafeteria, the N tables are all ordered in one line, where table number 1 is the closest to ...
- 公用的cefsharp窗口
书接上回,.net实现一个nw,一个字,简单. 结构,无废话,上图. 要说这部分上回展示过的,大致结构如此,其实要说清楚结构,还是得从工作流程开始说起 流程 1.通过桌面的快捷方式启动WebOnDes ...
- ORB-SLAM(五)KeyFrame类
KeyFrame类利用Frame类来构造.对于什么样的Frame可以认为是关键帧以及何时需要加入关键帧,是实现在tracking模块中的. 由于KeyFrame中一部分数据会被多个线程访问修改,因此需 ...
- luogu4172 [WC2006]水管局长
就是用 lct 维护最小生成树 ref #include <algorithm> #include <iostream> #include <cstdio> #in ...