题目大意:有$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的更多相关文章

  1. codeforces - 15C Industrial Nim(位运算+尼姆博弈)

    C. Industrial Nim time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...

  2. codeforces 15C. Industrial Nim

    题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...

  3. Industrial Nim

    http://codeforces.com/contest/15/problem/C 题意: 现有n个采石场,第i个采石场有mi堆石子 各堆分别有xi,xi+1……,xi+m-1颗石子 两名选手使用最 ...

  4. Codeforces 15C Industrial Nim 简单的游戏

    主题链接:点击打开链接 意甲冠军: 特定n 下列n行,每一行2的数量u v 表达v礧:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先依据Nim的博弈结论 把全部数都异或一下, ...

  5. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  8. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  9. 【SRM】518 Nim

    题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...

随机推荐

  1. HTML基础全荟

    第一讲 html概述 1.认识HTML <! DOCTYPE html> <html> <style></style> <head>< ...

  2. php访问url(get和post请求)

    get请求 /* * php访问url路径,get请求 */ function curl_file_get_contents($durl){ // header传送格式 $headers = arra ...

  3. python3 练习题100例 (十一)

    题目十一:举例证明角谷猜想:以一个正整数N为例,如果N为偶数,就将它变为N/2,如果除后变为奇数,则将它乘3加1(即3N+1).不断重复这样的运算,经过有限步后,一定可以得到1. #!/usr/bin ...

  4. ssh 远程命令

    远程拷贝文件,scp -r 的常用方法: 1.使用该命令的前提条件要求目标主机已经成功安装openssh-server 如没有安装使用 sudo apt-get install openssh-ser ...

  5. ruby 数据类型Number

    Ruby支持的数据类型包括基本的Number.String.Ranges.Symbols,以及true.false和nil这几个特殊值,同时还有两种重要的数据结构——Array和Hash 数值类型(N ...

  6. PublicCMS 网站漏洞 任意文件写入并可提权服务器权限

    PublicCMS是目前网站系统中第一个采用JAVA架构 TOMCAT+Apcche+Mysql数据库架构的CMS网站,开源,数据承载量大,可以承载到上千万的数据量,以及用户的网站并发可达到上千万的P ...

  7. Python3爬虫(十三) 爬取动态页之Selenium

    Infi-chu: http://www.cnblogs.com/Infi-chu/ Python提供了很多模拟浏览器运行的库,比如:Selenium.Splash等 1.常用的引用 from sel ...

  8. YSZOJ:#247. [福利]可持久化线段树 (最适合可持久化线段树入门)

    题目链接:https://syzoj.com/problem/247 解题心得: 可持久化线段树其实就是一个线段树功能的加强版,加强在哪里呢?那就是如果一颗普通的线段树多次修改之后还能知道最开始的线段 ...

  9. 也谈js传值和传址

    通常的认识就是基本的数值元素是传值,对象等复杂结构传址,无需争论,一试便知. 首先是数值 var a = 1 var b = a a = 2 console.log(a) console.log(b) ...

  10. EAS_Table

    SHR人力 员工表 T_BD_PERSON fbirthday 出生日期 femployeetypeid       员工状态   员工状态  T_HR_BDEMPLOYEETYPE        T ...