您的位置:首页 > 其它

CodeForces 641 C.Little Artem and Dance(水~)

2017-04-28 13:17 561 查看
Description

n对男女顺时针站在一个环的n个位置上跳舞(n为偶),起初编号为i的男生和编号为i的女生在第i个位置跳舞,有两种操作:

1 x:所有男生移动x个位置,x为正则顺时针移动,为负则逆时针移动

2:和编号为i的女生跳舞的男生与和编号为i+1的女生跳舞的男生互换,i=1,3,…,n-1

给出q个操作,问操作后与第i个女生跳舞的男生编号

Input

第一行两整数n和q表示男生人数和操作数,之后q行每行一个操作(2<=n<=1e6,1<=q<=2e6,-n<=x<=n)

Output

输出n个整数表示和第i个女生跳舞的男生编号

Sample Input

6 3

1 2

2

1 2

Sample Output

4 3 6 5 2 1

Solution

注意到,两种操作都不会改变奇数编号男生相对位置以及偶数编号男生相对位置,所以只需要对编号为1和编号为2的男生进行这些操作即可

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111111
int n,q,ans[maxn];
int main()
{
while(~scanf("%d%d",&n,&q))
{
int a=0,b=1;
while(q--)
{
int type,x;
scanf("%d",&type);
if(type==2)a^=1,b^=1;
else
{
scanf("%d",&x);
a=((a+x)%n+n)%n;
b=((b+x)%n+n)%n;
}
}
for(int i=a,j=b,k=1;k<=n/2;i=(i+2)%n,j=(j+2)%n,k++)
ans[i]=2*k-1,ans[j]=2*k;
for(int i=0;i<n;i++)printf("%d%c",ans[i],i==n-1?'\n':' ');
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: