CodeForces 668B Little Artem and Dance
2 second
256 megabytes
standard input
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:
- 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 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.
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 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.
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,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的更多相关文章
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 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 ...
- CodeForces 669D Little Artem and Dance
模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...
- 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 ...
- 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 ...
- D. Little Artem and Dance
题目链接:http://codeforces.com/problemset/problem/669/D D. Little Artem and Dance time limit per test 2 ...
- D. Little Artem and Dance(带环模拟 + 规律)
D. Little Artem and Dance Little Artem is fond of dancing. Most of all dances Artem likes rueda - Cu ...
- 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. ...
- codeforces668b //Little Artem and Dance// Codeforces Round #348
题意:2种操作,转动或者奇偶位互换. 不论怎么交换,1的后两位一定是3,3的后两位一定是5.因此只要记录1,2的位置. //#pragma comment(linker,"/STACK:10 ...
随机推荐
- 解决异常断电导致的: CorruptSSTableException: java.io.EOFException
问题产生 服务器重启,导致cassandra损坏,整个集群不可用.所使用的cassandra为2.1.9版本. 问题描述 运行启动命令,报错如下: DEBUG :: All segments have ...
- 清理iOS中的“其他”空间垃圾文件
关于如何清理 iOS 里的"其他"空间的教程,网上搜索那是一大堆,不过都是对于2010年某坛某篇"技术文"的无数次简单复制粘帖,可行性已经被各路尝试者们踩到了地 ...
- windows config yii framework
download and config download yii-1.1.12 unzip into yii-1.1.12 config yii-1.1.12 dir an apache httpdo ...
- docker构建测试环境
构建测试环境首先要根据自己的需求,构建出适合自己项目的image,有了自己的image,就可以快速的搭建出来一套测试环境了. 下边就说一下构建image的两种方式. 1.DOCKFILE创建文件夹:m ...
- COCOS2D-HTML5 开发之二】cocos2d-html5项目定义成员,局部变量,函数笔记随笔
本站文章均为李华明Himi原创,转载务必在明显处注明:(作者新浪微博:@李华明Himi) 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/cocos2d- ...
- bootstrap 模式对话框
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- C++ STL标准模板库(list)
//list的使用 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<list> using namesp ...
- easy ui 验证框的使用
Easy ui 插件之validatebox missingMessage:未填写时显示的信息validType:验证类型见下示例invalidMessage:无效的数据类型时显示的信息require ...
- petrozavodsk summer 2018 游记&&总结
day0: 出发前训了一场比较水bapc2017保持手感(恢复信心),成功AK了,不过罚时略高.然后三人打车从紫金港到杭州东站,坐高铁到上海虹桥,再坐机场快线到浦东机场(傻乎乎的jsb帮爸爸付了钱,然 ...
- js indexof用法indexOf()定义和用法
indexOf()定义和用法 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. 语法 stringObject.indexOf(searchvalue,fromindex) ...