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 ...
随机推荐
- 使用Rancher搭建K8S测试环境
使用Rancher搭建K8S测试环境 http://blog.csdn.net/csdn_duomaomao/article/details/75316926 环境准备(4台主机,Ubuntu16.0 ...
- PythonPath在Windows 下的设置
今天在调试Evernote SDK时, 遇到PythonPath的问题. 查了很多资料,有说用系统环境变量添加PythonPath, 有说在注册表中的PythonPath添加新Default字段, 但 ...
- mina中的发送延时
由于项目需要,用到了 mina 框架进行 tcp 通讯.我是初次接触 mina,于是从 Hello world 开始学习了 mina .期间遇到了一个奇怪的发送数据的延迟问题,解决的过程是曲折的,但找 ...
- PG peered实验
标签(空格分隔): ceph,ceph实验,pg 1. 创建一个文件,并把该文件作为对象放到集群中: [root@node1 ~]# echo "this is test! " & ...
- hibernate 数据关联一对多
一对多,多对一 (在多的一端存放一的外键) 但是在实体类中不需要创建这个外键 // 在一的一方创建Set集合 public class User { private Integer id; priva ...
- (cdh)hive 基础知识 名词详解及架构
过程 启动 hive 之后出现的 CLI 是查询任务的入口,CLI 提交任务给 Driver Driver 接收到任务后调用 Compiler,Executor,Optimizer 将 SQL 语句转 ...
- LAMP 1.5 测试PHP解析 问题解决
安装完php从新加载了一个模块 php5_module 重新启动模块 /usr/local/apache2/bin/apachectl restart ifconfig 查看本机ip,在浏览器里面输入 ...
- Python学习:命令行运行,循环结构
一.安装配置和运行方法 1.安装OpenCV 3.1: 假设安装目录为"C:\Python34" 2.配置环境变量: 方法一:直接配置:打开"控制面板",搜索& ...
- require用法及源码解析
一.require()的基本用法 require语句内部逻辑: 当 Node 遇到 require(X) 时,按下面的顺序处理. (1)如果 X 是内置模块(比如 require('http')) ...
- [51nod1270] 数组的最大代价(简单dp)
解题关键:先由贪心的思想得出任何一个位置只能取1或者a[i],然后dp即可. #include<bits/stdc++.h> using namespace std; typedef lo ...