B. Little Artem and Dance
time limit per test

2 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 2dances
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:

  1. Value x and some direction are announced, and all boys move x positions
    in the corresponding direction.
  2. 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 3swaps
    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
input
6 3
1 2
2
1 2
output
4 3 6 5 2 1
input
2 3
1 1
2
1 -2
output
1 2
input
4 2
2
1 3
output

1 4 3 2

先把1,2的位置确定了,

别的数字的位置变动和1,2肯定是一样的

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
#define MAX 1000000
int n,q;
int c[MAX+5];
int x,y;
int main()
{
scanf("%d%d",&n,&q);
int a=1;int b=2;
for(int i=1;i<=q;i++)
{
scanf("%d",&x);
if(x==1)
{
scanf("%d",&y);
a=(a+y+n)%n;
if(a==0)
a=n;
b=(b+y+n)%n;
if(b==0)
b=n;
}
else
{
if(a&1) a+=1;
else a-=1;
if(b&1) b+=1;
else b-=1;
}
}
a-=1;
b-=2;
for(int i=1;i<=n;i++)
{
if(i&1)
{
int pos=(i+a)%n;
if(pos==0)
pos=n;
c[pos]=i;
}
else
{
int pos=(i+b)%n;
if(pos==0)
pos=n;
c[pos]=i;
}
}
for(int i=1;i<=n;i++)
{
if(i==n)
printf("%d\n",c[i]);
else
printf("%d ",c[i]);
}
return 0; }

CodeForces 668B Little Artem and Dance的更多相关文章

  1. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  2. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

  3. CodeForces 669D Little Artem and Dance

    模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  5. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. D. Little Artem and Dance

    题目链接:http://codeforces.com/problemset/problem/669/D D. Little Artem and Dance time limit per test 2 ...

  7. D. Little Artem and Dance(带环模拟 + 规律)

    D. Little Artem and Dance Little Artem is fond of dancing. Most of all dances Artem likes rueda - Cu ...

  8. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  9. codeforces668b //Little Artem and Dance// Codeforces Round #348

    题意:2种操作,转动或者奇偶位互换. 不论怎么交换,1的后两位一定是3,3的后两位一定是5.因此只要记录1,2的位置. //#pragma comment(linker,"/STACK:10 ...

随机推荐

  1. NoSQL(三)

    redis集群介绍 1.官方叫cluster,redis3.0才直接的一个架构,如果数据量很大,单台机器已经无法满足存储,查询的瓶颈,所以我们需要多台机器构成一个大集群,用来解决存储空间,查询速度,负 ...

  2. python-循环(loop)-for循环

    for 循环 for every_letter in 'Hello world': print(every_letter) 输出结果为 把 for 循环所做的事情概括成一句话就是:于...其中的每一个 ...

  3. import { Subject } from 'rxjs/Subject';

    shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...

  4. 点滴积累【other】---存储过程删除所有表中的数据(sql)

    USE [QG_Mis24] GO /****** Object: StoredProcedure [dbo].[p_set1] Script Date: 07/18/2013 13:25:57 ** ...

  5. Atitit.使用引擎加脚本架构的设计 使用php,js来开发桌面程序。。

    Atitit.使用引擎加脚本架构的设计 使用php,js来开发桌面程序.. 1. 引擎加脚本架构 跨平台,桌面与web的优势1 2. 架构桌面引擎(java,c#)2 3. php桌面引擎要点2 3. ...

  6. [svc]linux文件特殊权限

    这是老以前写的文章, 断断续续的可见那时候的心态还是不稳的. 生产使用: g1,g2组2个组的员工,  g2组要访问g1组/home下的文件,rx权限.  这个setfacl就有用. 方法1: 修改普 ...

  7. mysql 一些常用指令

    登陆: mysql -u root -p //登陆,输入root密码 退出登陆 mysql>exit; mysql 为所有ip授权 mysql> GRANT ALL PRIVILEGES ...

  8. 前端点击删除按钮删除table表格的数据

    table.on('tool(hostTable)', function (obj) { var data = obj.data;//须写 if (obj.event === 'del') { var ...

  9. 本地测试Tomcat配置Https访问

    一.tomcat开启HTTPS配置 1) 准备证书 使用jdk工具keytool生成一个ssl测试用证书, 一路按照提示操作输入即可 keytool -genkey -alias tomcat -ke ...

  10. deepin linux 下C开发环境配置

    # deepin linux 下C开发环境配置 ## 前言-----------------------------deepin操作系统商店默认提供了 eclipse for c\c++但是系统没有提 ...