CodeForces 705B Spider Man(蜘蛛侠游戏)
2016-08-11 23:21
190 查看
http://codeforces.com/problemset/problem/705/B
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 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 least 2 vertices (for example, x vertices)
among all available cycles and replace it by two cycles with p andx - p vertices
where 1 ≤ 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.
Input
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 integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th
of them stands for the number of vertices(顶点)in the cycle added before the i-th
test.
Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
Examples
input
output
input
output
Note
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 with 2.
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 size 1 and one with
size 2. Now cycles have 1, 1, 2, 2 vertices(顶点).
Second player's only move is to replace a cycle of size 2 with 2 cycles
of size 1. And cycles are 1, 1, 1, 1, 2.
First player replaces the last cycle with 2 cycles with size 1and
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 sizes 1 and 4 or 2and 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 size 1. 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 sizes 1 and 2.
Now only cycles with more than one vertex(顶点) are two cycles of size 2.
As shown in previous case, with 2 cycles of size 2 second
player wins.
So, either way first player loses.
Code:
#include<stdio.h>
int main() {
int n,ans=2;
while(scanf("%d",&n)!=EOF) {
for(int j=1; j<=n; j++) {
int id;
scanf("%d",&id);
if(id%2==0) ans=(ans+1)%3;
if(ans==0) ans=ans+1;
printf("%d\n",ans);
}
// puts("");
}
return 0;
}
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 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 least 2 vertices (for example, x vertices)
among all available cycles and replace it by two cycles with p andx - p vertices
where 1 ≤ 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.
Input
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 integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th
of them stands for the number of vertices(顶点)in the cycle added before the i-th
test.
Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
Examples
input
3 1 2 3
output
2 1 1
input
5 1 1 5 1 1
output
2 2 2 2 2
Note
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 with 2.
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 size 1 and one with
size 2. Now cycles have 1, 1, 2, 2 vertices(顶点).
Second player's only move is to replace a cycle of size 2 with 2 cycles
of size 1. And cycles are 1, 1, 1, 1, 2.
First player replaces the last cycle with 2 cycles with size 1and
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 sizes 1 and 4 or 2and 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 size 1. 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 sizes 1 and 2.
Now only cycles with more than one vertex(顶点) are two cycles of size 2.
As shown in previous case, with 2 cycles of size 2 second
player wins.
So, either way first player loses.
Code:
#include<stdio.h>
int main() {
int n,ans=2;
while(scanf("%d",&n)!=EOF) {
for(int j=1; j<=n; j++) {
int id;
scanf("%d",&id);
if(id%2==0) ans=(ans+1)%3;
if(ans==0) ans=ans+1;
printf("%d\n",ans);
}
// puts("");
}
return 0;
}
相关文章推荐
- 【模拟】Codeforces 705B Spider Man
- CodeForces 705B Spider Man 思维游戏题
- 【模拟】Codeforces 705B Spider Man
- CodeForces 705B Spider Man
- CodeForces 705B Spider Man
- 【Codeforces Round #366 (Div. 2)】Codeforces 705B Spider Man
- 关于(a+b)/3的证明--codeforces,519c.
- codeforces 651B Beautiful Paintings【优先队列】
- CodeForces - 515C Drazil and Factorial
- Problem--266A--Codeforces--Stones on the Table
- Codeforces-708C(树形DP)
- Codeforces Good Bye 2017 Div.2 908A,B
- Codeforces 519D A and B and Interesting Substrings (前缀和)
- Codeforces 86C Genetic engineering(AC自动机+DP)
- 【模拟】Codeforces 704A & 705C Thor
- codeforces 291 E. Tree-String Problem (dfs+kmp)
- CodeForces 161D [Distance in Tree] 点分治
- Codeforces 939B(Hamster Farm)
- Codeforces 117C DFS形成环
- Codeforces 398C Tree and Array 构造