Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接

题意:

给定n

下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1

问先手必胜还是后手必胜

思路:

首先根据Nim的博弈结论

把所有数都异或一下,看结果是0还是非0

而这里因为数字太多所以想优化

那么其实对于一个序列 u, u+1, u+2 ····

显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1

那么只需要把序列分组,分成{偶数,奇数}

然后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 __int64
ll 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;
}

Codeforces 15C Industrial Nim 简单博弈

时间: 2024-08-04 17:19:21

Codeforces 15C Industrial Nim 简单博弈的相关文章

codeforces 15C. Industrial Nim

题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性质. 一共给出了$n$段石头堆,每段中石头堆的数量是连续的. 在$x$是偶数时${x^(x+1)=1}$,利用这个性质我们就可以${O(1)}$的算出每一段石头的异或和. 1 #include<iostream> 2 #include<cstdio> 3 #include<alg

【打CF,学算法——二星级】Codeforces 705B Spider Man (简单博弈)

[CF简介] 题目链接:CF 705B 题面: B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of v

poj2975 Nim(经典博弈)

Nim Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5866   Accepted: 2777 Description Nim is a 2-player game featuring several piles of stones. Players alternate turns, and on his/her turn, a player’s move consists of removing one or mor

ACM: NBUT 1107 盒子游戏 - 简单博弈

NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format: Practice Appoint description:  System Crawler  (Aug 13, 2016 10:35:29 PM) Description 有两个相同的盒子,其中一个装了n个球,另一个装了一个球.Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作每次操作时,游戏者先看看

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

【HDU3032】【Lasker&#39;s Nim(一种Nim游戏)】Nim or not Nim? Multi-SG博弈、打表

转载请注明出处:http://blog.csdn.net/vmurder/article/details/42652745 其实我就是觉得原创的访问量比未授权盗版多有点不爽233... 题意:n堆石子,每次可以从某堆中拿走若干,也可以把此堆分成两个非空堆,谁无法操作了谁输. 题解:首先我们可以打个SG函数来暴力出解,但是显然这会T. 但是不要害怕,我们打完以后发现了一个貌似对的规律: 对于所有的k >= 0,有 sg( 4k+1 ) = 4k+1: sg( 4k+2 ) = 4k+2: sg(

CodeForces 30C Shooting Gallery 简单dp

题目链接:点击打开链接 给定n个气球 下面n行 x y t val 表示气球出现的坐标(x,y) 出现的时刻t,气球的价值val 枪每秒移动1个单位的距离 问: 射击的最大价值,开始时枪瞄准的位置任意. 思路: dp一下.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set

hdu 2999 sg函数(简单博弈)

Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 393    Accepted Submission(s): 132 Problem Description "Alice and Bob are playing stone game...""E