Spider Man CodeForces
来源:互联网 发布:java面向对象 编程题 编辑:程序博客网 时间:2024/05/16 16:08
Spider Man
CodeForces - 705BPeter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.
Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least2 vertices (for example, x vertices) among all available cycles and replace it by two cycles withp and x - p vertices where1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).
Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In thei-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?
Peter is pretty good at math, but now he asks you to help.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.
The second line contains n space separated integersa1, a2, ..., an (1 ≤ ai ≤ 109),i-th of them stands for the number of vertices in the cycle added before thei-th test.
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
31 2 3
211
51 1 5 1 1
22222
In the first sample test:
In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.
In his second test, there's one cycle with 1 vertex and one with2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can't make any move and loses.
In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size1 and one with size 2. Now cycles have1, 1, 2, 2 vertices. Second player's only move is to replace a cycle of size2 with 2 cycles of size1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size1 and wins.
In the second sample test:
Having cycles of size 1 is like not having them (because no one can make a move on them).
In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes1 and 4 or 2 and 3.
- If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size1. Second player does the same thing with the other cycle. First player can't make any move and loses.
- If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes1 and 2. Now only cycles with more than one vertex are two cycles of size2. As shown in previous case, with 2 cycles of size 2 second player wins.
So, either way first player loses.
题意:
博弈游戏,一堆数,可以拆成两堆非空的,所有堆都不能拆,则为输。每次不断加入一个新堆,问在当前所有堆的情况下的输赢状况。
解题:
因为一个数字n,可以拆的次数为固定的n-1次,故而只要统计全部的可操作次数,看总和的奇偶性即可。
(因此每次加入新的数后,开始的顺序是延续上一次的顺序,上一次到哪里了就从谁开始,即次数累加)
code:
#include <iostream>#include <cmath>using namespace std;int main(){ int n; cin >> n; int sum = 0; int i,temp; for(i = 0; i < n; i++){ cin >> temp; sum += temp-1;//每个数有n-1次拆分 if(sum&1)//是奇数最后一个肯定是先手 cout << "1" << endl; else//是偶数说明一人一次正平分,最后一个能拆分的是后手 cout << "2" << endl; } return 0;}
- Spider Man CodeForces
- Codeforces-705B-Spider Man
- CodeForces 705B Spider Man
- Codeforces 705B.Spider Man
- codeforces 705 B. Spider Man (思维)
- 【模拟】Codeforces 705B Spider Man
- Spider Man
- 【Codeforces Round #366 (Div. 2)】Codeforces 705B Spider Man
- Codeforces #366(Div.2)B.Spider Man【水题】
- CodeForces 705B Spider Man(蜘蛛侠游戏)
- CodeForces 705B Spider Man 思维游戏题
- CodeForces704B Spider Man
- codeforces705B B. Spider Man
- B. Spider Man
- Codeforces Round #366 (Div. 2) B. Spider Man (组合游戏)
- 【打CF,学算法——二星级】Codeforces 705B Spider Man (简单博弈)
- Codeforces Round #366 (Div. 2) B. Spider Man (Nim游戏)
- Spider-Man: Total Mayhem(蜘蛛侠)
- JZOJ 5485 字符串
- 学习《JS高级程序设计》(5)——正则
- 将文件复制到ftp服务器时发生错误
- 使用synchronized实现死锁
- nginx,rewrite,proxy_pass,post数据,表单
- Spider Man CodeForces
- C++构造函数的三个作用
- L1-034. 点赞
- Android应用内多进程的使用及注意事项
- Asynchronous Methods for Deep Reinforcement Learning 阅读笔记
- $.ajax 中的contentType
- 使用ajax和json实现迭代数据的效果
- 使用eclipse插件创建一个web project
- Matlab报错问题