codeforces 669D D. Little Artem and Dance(乱搞题)
题目链接:
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 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 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.
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 题意: 两种变换,一种是按顺时针或者逆时针移动,另一种是按女孩的奇偶数进行交换;
问最后得序列是多少; 思路: 我又大开脑洞搞些奇怪的玩意来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 ;
}
codeforces 669D D. Little Artem and Dance(乱搞题)的更多相关文章
- CF_402C Searching for Graph 乱搞题
题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...
- Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)
题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...
- Codeforces 1182D Complete Mirror 树的重心乱搞 / 树的直径 / 拓扑排序
题意:给你一颗树,问这颗树是否存在一个根,使得对于任意两点,如果它们到根的距离相同,那么它们的度必须相等. 思路1:树的重心乱搞 根据样例发现,树的重心可能是答案,所以我们可以先判断一下树的重心可不可 ...
- codeforces 653C C. Bear and Up-Down(乱搞题)
题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- codeforces 664B B. Rebus(乱搞题)
题目链接: B. Rebus time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 1513F - Swapping Problem(分类讨论+乱搞)
Codeforces 题目传送门 & 洛谷题目传送门 简单题,难度 *2500 的 D2F,就当调节一下一模炸裂了的自闭的心情,稍微写写吧. 首先我看到这题的第一反应是分类讨论+数据结构,即枚 ...
- Codeforces 34C-Page Numbers(set+vector+暴力乱搞)
C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 685C - Optimal Point(分类讨论+乱搞)
Codeforces 题面传送门 & 洛谷题面传送门 分类讨论神题. 首先看到最大值最小,一眼二分答案,于是问题转化为判定性问题,即是否 \(\exists x_0,y_0,z_0\) 满足 ...
- CodeForces 509C Sums of Digits(贪心乱搞)题解
题意:a是严格递增数列,bi是ai每一位的和,告诉你b1~bn,问你怎样搞才能让an最小 思路:让ai刚好大于ai-1弄出来的an最小.所以直接模拟贪心,如果当前位和前一个数的当前位一样并且后面还能生 ...
随机推荐
- Golang中的panic和recover(捕获异常)
func panic(interface{})和func recover() interface{}是Golang中用于错误处理的两个函数. panic的作用就是抛出一条错误信息,从它的参数类型可以看 ...
- Objective C语言中nil、Nil、NULL、NSNull的区别
以下内容是基于搜集整理的网上资料,供参考. nil:指向Objective C语言中对象的空指针,其定义值为(id)0. Nil:指向Objective C语言中类(Class)的空指针,其定义值为( ...
- html5对各浏览器的支持情况
考虑到HTML5标准的制定原则:新特性基于HTML.CSS.DOM 以及 JavaScript:减少对外部插件的需求(比如Flash):独立于设备等,我们选取了HTML 5的几项主要特性来评价浏览器系 ...
- 小程序-列表块/类式ul-li格式(1)
摘要 目前列表能布局出来,但是目前我个人还没解决的问题是:如果每个列表块都有详情页怎么解决呢? 1:我的效果图 2.正常的每个都能点击的html 注:上面的代码确实能够实现我的每个[menu2_vie ...
- T1230 元素查找 codevs
http://codevs.cn/problem/1230/ 题目描述 Description 给出n个正整数,然后有m个询问,每个询问一个整数,询问该整数是否在n个正整数中出现过. 输入描述 In ...
- Java生成读取条形码和二维码图片
原文:http://www.open-open.com/code/view/1453520722495 package zxing; import com.google.zxing.BarcodeFo ...
- 【flyway】Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' def
报错如下: "2018-03-20 12:58:09.585 WARN 18026 — [ restartedMain] ConfigServletWebServerApplicationC ...
- magic packet 远程唤醒需填写 IP broadcast address
之前摸索过电脑,知道hp compaq6910p有远程唤醒功能的.当时没在意.如今忽然有了实际的需求,就想起来折腾一下了.看了网上的做法,主要是双方面设置,BIOS和网卡.之后就能够用magic pa ...
- IOS开发 二维码功能的实现
原帖地址:http://yul100887.blog.163.com/blog/static/20033613520121020611299/ 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二 ...
- IoT设备程序开发及编译环境搭建初体验
引言 Mirai事件一经曝出,立即引领了一轮研究IoT设备的热潮.目前,对Mirai的报告大多只是在对其功能实现上的介绍,却很少提及如何实现IoT设备程序开发的测试环境.本文在对Mirai的源码研究的 ...