D. Little Artem and Dance
题目链接:http://codeforces.com/problemset/problem/669/D
2 seconds
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 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.
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 题目大意:输入n,代表有n对男女,1···n。所有人围成一个圈, 刚开始男1与女1,男2与女2···对应,q代表有q次操作,如果输入的是1,则所有男的移动x位,正代表顺时针,负代表逆时针。如果输入的是2,则男1与男2交换位子,男3与
男4交换位子···
个人思路:不论怎么操作,其实男1后面两位一定是3,后面4位一定是5·····男2后面两位一定是4,后面四位一定是6····,所以我们只要记录男1和男2的位子,就能知道所有人的位子了
看代码(但这题要用scanf,不然会超时)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
typedef long long ll;
using namespace std;
const ll mod=1e9+;
const int maxn=1e6+;
const int maxk=+;
const int maxx=1e4+;
const ll maxa=;
#define INF 0x3f3f3f3f3f3f
int a[maxn];
int main()
{
int n,q,p1,p2,m,x;
scanf("%d%d",&n,&q);
p1=;
p2=;
for(int i=;i<=q;i++)
{
scanf("%d",&m);
if(m==)
{
scanf("%d",&x);
if(x<)
x+=n;
p1+=x;
p2+=x;
p1%=n;
p2%=n;
}
else
{
if(p1%==)
{
p1+=;
}
else
{
p1-=;
//p1=(p1+n)%n;
}
if(p2%==)
{
p2+=;
}
else
{
p2-=;
// p2=(p2+6)%6;
}
}
}
a[p1]=;
a[p2]=;
int t=n/;
int sum=;
while(--t)
{
sum+=;
a[(p2+)%n]=sum;
p2=(p2+)%n;
}
t=n-n/;
sum=;
while(--t)
{
sum+=;
a[(p1+)%n]=sum;
p1=(p1+)%n;
}
for(int i=;i<n;i++)
printf("%d ",a[i]);
printf("\n");
return ;
}
D. Little Artem and Dance的更多相关文章
- 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 668B Little Artem and Dance
B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...
- 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 ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 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. ...
- CodeForces 669D Little Artem and Dance
模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...
- codeforces668b //Little Artem and Dance// Codeforces Round #348
题意:2种操作,转动或者奇偶位互换. 不论怎么交换,1的后两位一定是3,3的后两位一定是5.因此只要记录1,2的位置. //#pragma comment(linker,"/STACK:10 ...
- CodeForces - 669D Little Artem and Dance 想法题 多余操作
http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...
随机推荐
- Poj 1552 Doubles(水题)
一.Description As part of an arithmetic competency program, your students will be given randomly gene ...
- [转] 更新Flash CS6发布设置的目标播放器版本
目前Aodbe发布的最新版的Flash CS6,都不支持将Flash Player 11作为目标播放器版本发布.这个问题很容易解决,但涉及到的东西却比较多,我在这里将一一讲解.首先来个Setp by ...
- SQL常用语法及规则-表格的操作
一.规则和标准 1)每一行SQL语句结尾,加分号: 2)所创建的对象,名字用反引号(不是引号,与~同一个键): 3)一般关键字或保留字要大写: 4)两个中划线 + 空格(-- ),后面的语句为注释语句 ...
- JAVA 1.5 并发之 Executor框架 (内容为转载)
本文内容转自 http://www.iteye.com/topic/366591 Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Exec ...
- java基础知识学习 java异常
1: Unchecked Exception( 也就是运行时异常) VS Check Exception(非运行时异常) 2: 运行期异常 VS 非运行期异常? 非运行时异常: 必须在代码中显示 ...
- Spring boot 学习一:认识Spring boot
什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...
- SpringMVC执行流程简介
1.用户向服务器发送请求,请求被SpringMVC的前端控制器DispatcherServlet截获. 2.DispatcherServlet对请求的URL(统一资源定位符)进行解析,得到URI(请求 ...
- JS ES6 -- let命令
1.ES6新增了块级作用域的let和const 这新特性let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. for循环的计数器,就很合适使用let命令 ...
- excel2003, 2007最大行列、sheet数
1.excel2003版本一个工作表最多可有65536行,行用数字1—65536表示; 256列,列用英文字母A—Z,AA—AZ,BA—BZ,……,IA—IV表示.2.一个工作簿中最多含有25 ...
- JConsole远程监控配置
首先,看本机(Windows)安装了JRE没 Win > CMD 打开命令窗口 如有安装,则会显示以下版本信息:若没有显示,就安装吧 C:\Users\Administrator>java ...