思维题,加强读题能力CodeForces - 705B
#include<iostream>
using namespace std;
int main()
{
int n,i;
long long sum,x;
cin>>n;
sum=0;
for(i=1;i<=n;i++){
cin>>x;
sum=sum+x-1;
if(sum%2){
cout<<"1"<<endl;
sum=1;
}
else{
cout<<"2"<<endl;
sum=0;
}
}
return 0;
}||偶数就是后手赢,奇数就是先手赢
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
- Value x and some direction are announced, and all boys move x positions in the corresponding direction.
- Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.
Your task is to determine the final position of each boy.
Input
The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.
Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.
Output
Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.
Examples
6 3
1 2
2
1 2
4 3 6 5 2 1
2 3
1 1
2
1 -2
1 2
4 2
2
1 3
1 4 3 2
这道题目就是求男生的位置,女生位置不变。有两种指令,一个是输入1,然后输入x,x表示移动多少个单位,第二种指令时2,交换奇数偶数女生的男伴的位置。一开始以为很多种变化情况,后面看
了别人的博客,发现无论怎么变化,奇数男生的相对位置都是不变的,比如3号男生始终在1号男生的位置加2的地方。偶数一样分析。
知道了这个代码就好写了,只需要记录1号2号男生的位置,后面的男生位置就都出来了。
#include<stdio.h> #include<string.h> using namespace std; int a[1000600]; int p[2000600][2]; int ans[1000600]; int main() { int n,q; while(~scanf("%d%d",&n,&q)) { int now=1; int now2=2; memset(ans,0,sizeof(ans)); for(int i=0;i<q;i++) { scanf("%d",&p[i][0]); if(p[i][0]==1) { scanf("%d",&p[i][1]); now+=p[i][1]; now2+=p[i][1]; } if(p[i][0]==2) { if(now%2==1)now+=1; else now-=1; if(now2%2==1)now2+=1; else now2-=1; } if(now>n)now-=n; if(now<1)now+=n; if(now2>n)now2-=n; if(now2<1)now2+=n; } int cnt=1; int t=n/2; while(t--) { ans[now]=cnt; ans[now2]=cnt+1; cnt+=2; now+=2; now2+=2; if(now>n)now-=n; if(now<1)now+=n; if(now2>n)now2-=n; if(now2<1)now2+=n; } for(int i=1;i<=n;i++) { printf("%d ",ans[i]); } printf("\n"); } }