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 ...
随机推荐
- js 函数定义的两种方式以及事件绑定(扫盲)
一.事件(例如:onclick)绑定的函数定义放在jsp前面和放后面没影响 二. $(function() { function func(){}; }) onclick通过如下方式绑定事件到jsp中 ...
- BluetoothFindNextRadio 函数
BOOL BluetoothFindNextRadio( HBLUETOOTH_RADIO_FIND hFind, HANDLE* phRadio ); BluetoothFindNextRadio找 ...
- hive一些思考
Hive查询 1.hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供完整的sql查询功能,可以将sql语句转换为MapReduce任务进行运行.其优点是学习 ...
- C语言入门题
1. 如下语句通过算术运算和逻辑运算之后 i 和 j 的结果是() int i=0; int j=0; if((++i>0)||(++j>0 ...
- [51nod1247]可能的路径(思维题)
题意:给定(a,b),(x,y) ,(a,b)可以通向(a-b,b) (a+b,b) (a,a+b) (a,a-b) 求能否到达(x,y) 解题关键:类似于更相减损,变换过程中gcd是一样的. #i ...
- [hdu1712]ACboy needs your help分组背包
题意:一共$m$天,$n$门课程,每门课程花费$i$天得到$j$的价值,求最后获得的最大价值 解题关键:分组背包练习,注意循环的顺序不能颠倒 伪代码: $for$ 所有的组$k$ $for{\rm ...
- 六种获取配置properties文件的方法
总结一下六种获取配置properties文件的方法,代码如下: package com.xujingyang.test ; import java.io.BufferedInputStream ; i ...
- Spring的概况
----------------siwuxie095 Spring 的简介 Spring 是一个轻量级 控制反转(IoC) 和 面向切面(AOP) 的容器框架 年,它是为了解决企业应用开发的复杂性而诞 ...
- Java Synchronized的原理
我们先通过反编译下面的代码来看看Synchronized是如何实现对代码块进行同步的: public class SynchronizedDemo{ public void method(){ syn ...
- 18.phpmyadmin 4.8.1 远程文件包含漏洞(CVE-2018-12613)
phpmyadmin 4.8.1 远程文件包含漏洞(CVE-2018-12613) phpMyAdmin是一套开源的.基于Web的MySQL数据库管理工具.其index.php中存在一处文件包含逻辑, ...