题目链接:

D. Little Artem and Dance

time limit per test

2 seconds

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 number3 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.

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

题意:

两种变换,一种是按顺时针或者逆时针移动,另一种是按女孩的奇偶数进行交换;
问最后得序列是多少; 思路: 我又大开脑洞搞些奇怪的玩意来A题了;哈哈哈哈,谁让我这么弱呢,弱到连参加水赛的机会都没有;
来说说我的奇葩的解法吧; 开两个队列,一个奇数队列,一个偶数队列,因为我发现最后得序列都是奇偶数交替出现,那么我们这两个队列里的相同位置的两个数是要相邻出现的;
但是在顺时针方向上这两个数出现的前后关系会变化而且与之对应的数也会发生相应的变化;
Lipoter表示的是在顺时针方向偶数在前边还是奇数在前边;变换后可以得到顺时针方向上的数的序列(即那两个数是相邻的);
这是序列关系搞定了,那么这个序列再最终的结果哪个是第一个呢?
我选取1这个shy boy 进行位置变换,最后得到1boy的最终位置,那这个shy boy的最终位置做标准就可以得到所有boy 的位置了;
1 3 5 7
2 4 6 7

假设初始的时候匹配(相邻)的关系是这样,那么自己体会代吧,哎,我要看看别人是怎么做的;

AC代码
/*2014300227    D - Little Artem and Dance    GNU C++11    Accepted    826 ms    10300 KB*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
const ll inf=1e15;
const int N=1e6+;
int n,q,b[N],t;
queue<int>even,odd,ans;
int main()
{
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++)
{
if(i%)odd.push(i);
else even.push(i);
}
int len,Lipoter=,flag=;
for(int i=;i<=q;i++)
{
scanf("%d",&t);
if(t==)
{
scanf("%d",&len);
flag=(flag+len+n)%n;
if(flag==)flag=n;
}
else
{
if(flag%){
if(Lipoter==)
{
even.push(even.front());//因为要与匹配的数字要变化,那么就移一位;
even.pop();
}
else Lipoter=;
}
else
{
if(Lipoter==)
{
odd.push(odd.front());
odd.pop();
}
else Lipoter=;
}
if(flag%)flag++;
else flag--;
if(flag==)flag=n;
}
}
if(Lipoter){
while(!even.empty()&&!odd.empty())
{
ans.push(odd.front());
odd.pop();
ans.push(even.front());
even.pop();
}
}
else
{
while(!even.empty()&&!odd.empty())
{
ans.push(even.front());
even.pop();
ans.push(odd.front());
odd.pop();
}
}
while()
{
if(ans.front()==)break;
else
{
ans.push(ans.front());
ans.pop();
}
}
while(flag<=n)
{
b[flag++]=ans.front();
ans.pop();
}
int cnt=;
while(!ans.empty())
{
b[cnt++]=ans.front();
ans.pop();
}
for(int i=;i<=n;i++)printf("%d ",b[i]);
return ;
}

最新文章

  1. SpringMVC之controller篇
  2. Material Design For Xamarin.Forms
  3. linux基础命令学习五(软件包管理、下载管理)
  4. IndexOf() LastIndexOf() Contains() StartsWith() EndsWith()方法比较
  5. JMM &amp; synchronized概述(转)
  6. VB.NET转C#代码的工具
  7. Unity3D 关于运动模型
  8. PHP连接Mysql服务器的操作
  9. 精通UNIX下C语言编程与项目实践
  10. C#查询XML解决“需要命名空间管理器”问题
  11. java方法重写和super关键字
  12. JQuery官方学习资料(译):遍历JQuery对象和非JQuery对象
  13. phpstorm对laravel的一些使用技巧
  14. 关于对CSS中超链接那部分的设置
  15. Centos 5 无法使用ifconfig命令
  16. 退出vim编辑器(转)
  17. Linux的SSH免密登录认证过程研究
  18. [博客迁移]探索Windows Azure 监控和自动伸缩系列1 - 连接中国区Azure
  19. kafak manager + zookeeper + kafka 消费队列快速清除
  20. 部署docker-registry私有仓库

热门文章

  1. Linux 下 GCC 编译共享库控制导出函数的方法
  2. LeetCode OJ--Partition List
  3. java使用jxl,自动导出数据excle,quartz自动发送邮件
  4. BZOJ——1611: [Usaco2008 Feb]Meteor Shower流星雨
  5. linux下eth0 lo wlan0
  6. WIP - 离散任务点击组件-错误:LOCATOR.CONTROL 的变元无效:ORG_LOCATOR_CONTROL=''
  7. 安卓自带下拉刷新SwipeRefreshLayout加入上拉刷新功能
  8. 走入asp.net mvc不归路:[4]说说Action有哪些常见成员
  9. IOS 获取设备本地音视频
  10. csu1116 Kingdoms 最小生成树-枚举状态