博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
阅读量:6197 次
发布时间:2019-06-21

本文共 2705 字,大约阅读时间需要 9 分钟。

D. Little Artem and Dance

题目连接:

Description

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.

Sample Input

6 3

1 2
2
1 2

Sample Output

4 3 6 5 2 1

Hint

题意

给你n个数,一开始是1 2 3 4 5 6 这样的

现在有两个操作,第一个操作是所有数向右边移动x个位置

第二个操作奇数和偶数的位置互换

题解:

比较显然就是,奇数和偶数位置的数的相对位置是不会变的

那么我们只要知道1和2这两个位置的数是啥就好了

然后交换的时候,我们就模拟一下这两个位置的交换就好了

代码

#include
using namespace std;int n,q;int a,b;int main(){ scanf("%d%d",&n,&q); b = 0,a = 0; for(int i=1;i<=q;i++) { int op; scanf("%d",&op); if(op==1) { int x;scanf("%d",&x); a = (n+a-x)%n; b = (n+b-x)%n; if(x%2)swap(a,b); } else { a = (a+n-1)%n; b = (b+n+1)%n; swap(a,b); } } for(int i=1;i<=n;i++) { if(i%2)cout<<(a+i-1+n)%n+1<<" "; else cout<<(b+i-1+n)%n+1<<" "; } cout<

转载地址:http://aqjca.baihongyu.com/

你可能感兴趣的文章
【原】使用VirtIE6代替IE6
查看>>
做网站都能给公司带来哪些好处?作用在哪里?
查看>>
[linux]ssh原理以及配置
查看>>
Android常用抓包工具之TcpDump
查看>>
第一次使用Android Studio时你应该知道的一切配置
查看>>
CentOS 6.7 源码搭建LNMP架构部署动态网站环境
查看>>
iOS开发UI篇—CAlayer(自定义layer)
查看>>
使用AspNetPager与GridView完成分页
查看>>
Spring4.1新特性——静态资源处理增强
查看>>
Java Date Time 教程-java.util.Calendar和GregorianCalendar
查看>>
深入浅出jcr之十 redolog 和 recovery.docx
查看>>
LeetCode 22 Generate Parentheses(生成括号)
查看>>
hdu 3306 Another kind of Fibonacci
查看>>
【SICP练习】116 练习3.42
查看>>
【sql查询与优化】3.操作多个表
查看>>
connecting docker containers on multiple hosts with open vswitch GRE
查看>>
linux网络实现分析(1)——数据包的接收(从网卡到协议栈)
查看>>
自定义 Lint 规则简介
查看>>
从volatile解读ConcurrentHashMap(jdk1.6.0)无锁读
查看>>
学习嵌入式的心得
查看>>