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
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; }
相关文章推荐
- codeforces 641 C Little Artem and Dance
- codeforces 669D D. Little Artem and Dance(乱搞题)
- CodeForces 641 A.Little Artem and Grasshopper(水~)
- CodeForces 641 B.Little Artem and Matrix(水~)
- CodeForces 641 E.Little Artem and Time Machine(BIT+map)
- 【CodeForces】669A - Little Artem and Presents
- Codeforces 669A Little Artem and Presents(数量不同送礼物)
- 【CodeForces】[669A]Little Artem and Presents
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
- ACM刷题之Codeforces————Little Artem and Presents
- CodeForces 669A Little Artem and Presents
- 【CodeForces】669A - Little Artem and Presents(找规律)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
- Codeforces Round #348 (div 2) D - Little Artem and Dance
- Codeforces #669 Div2. D. Little Artem and Dance(思维)
- ACM刷题之Codeforces———— Little Artem and Grasshopper
- D. Little Artem and Dance---cf669D(模拟)
- CodeForces 669A Little Artem and Presents
- codeforces 669B B. Little Artem and Grasshopper(水题)
- codeforces 668C - Little Artem and Random Variable