D. Little Artem and Dance---cf669D(模拟)
题目链接:http://codeforces.com/problemset/problem/669/D
给你n个数,一开始是1 2 3 4 5 6 ... n 这样的
现在有两个操作,第一个操作是所有数向右边移动x个位置
第二个操作奇数和偶数的位置互换
现在有Q个指令,问最后的序列是什么;
n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000)
由于数据范围比较大,但是我们可以发现所以得偶数他们相邻的总是2 4 6 8 10...奇数都是1 3 5 7 9 11...也就是说无论怎么变他们的相对位置是不变的,就是每个数(奇数或偶数)的前后总是固定的,
所以我们可以记录数字1和2的位置在哪里,然后依次填出最终答案;
为了方便我们下标从0开始;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
#define N 1000100
#define met(a, b) memset(a, b, sizeof(a)) int n, Q, a[N]; int main()
{
while(scanf("%d %d", &n, &Q)!=EOF)
{
met(a, ); int first = , second = , op, x; while(Q--)
{
scanf("%d", &op);
if(op == )
{
scanf("%d", &x);
first = (x + first + n) % n;
second = (x + second + n) % n;
}
else
{///如果1所在位置下标是偶数(相对于下标为0来说的),那么1的位置就要往后挪一位,2则相反;
if(first%)
{
first = (first - + n) % n;
second = (second + + n) % n;
}
else
{
first = (first + + n) % n;
second = (second - + n) % n;
}
}
}
int num = ;
while(num <= n)///填入n个数
{
a[first] = num++;///奇数所在位置
a[second] = num++;
first = (first+) % n;///要加两个的,
second = (second+) % n;
}
for(int i=; i<n; i++)
printf("%d%c", a[i], i==n-?'\n':' ');
}
return ;
}
/*
6 9
2
1 -2
2
1 -6
1 -6
1 4
2
1 -1
2 2 5 4 1 6 3
*/
D. Little Artem and Dance---cf669D(模拟)的更多相关文章
- 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 ...
- 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 668B Little Artem and Dance
B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...
- D. Little Artem and Dance
题目链接:http://codeforces.com/problemset/problem/669/D D. Little Artem and Dance time limit per test 2 ...
- 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:序列中相邻的奇偶位置互 ...
- POJ 3344 & HDU 2414 Chessboard Dance(模拟)
题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...
- UVALive 4222 /HDU 2961 Dance 大模拟
Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...
- CodeForces 669D Little Artem and Dance
模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...
- CodeForces - 669D Little Artem and Dance 想法题 多余操作
http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...
随机推荐
- perl 中的哈希赋值
在perl 中,通过代码动态的给哈希赋值,是最常见的应用场景,但是有些情况下,我们事先知道一些信息,当需要把这些信息存放进一个哈希的时候,直接给哈希赋值就好: 哈希的key不用说,就是一个字符串,关键 ...
- ceRNA 调控机制
ceRNA 不同于mRNA, lncRNA, ncRNA 等概念,其指的既不是某一种类型的RNA(比如mRNA, lncRNA), 也不是某一类的RNA(如ncRNA); ceRNA 其实指的是不同种 ...
- Unity-Animator(Mecanim)深入系列总索引
花了不少时间完成了这篇Unity Animator学习系列文章,其中大多数内容都来自个人实践,包括API部分很多都是亲测,期望和网上的诸多教程达到互补. 相关参考文档 Unity Animator官方 ...
- nginx配置技巧汇总
https://segmentfault.com/a/1190000000437323
- layui时间,table,大图查看,弹出框,获取音频长度,文件上传
1.引入: <link href="../../Scripts/layui-v2.3.0/css/layui.css" rel="stylesheet" ...
- source insight 如何建工程--以及快捷方式查找调用函数方法
在source insight的view菜单中点出relation window,然后右键点relation window,选relation window properties,然后把view re ...
- EF更新的时候出错
错误提示: 存储区更新.插入或删除语句影响到了意外的行数(0).实体在加载后可能被修改或删除.刷新 ObjectStateManager 项. 说明: 执行当前 Web 请求期间,出现未经处理的异常. ...
- 服务器报错 500,请确保 ASP.NET State Service(ASP.NET 状态服务)已启动
报错信息: 解决方案: 开启此服务
- [IIS] IIS Framework "aspnet_regiis.exe" 注册
Error:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“
- Android 通过Socket 和服务器通讯
Extends:(http://www.cnblogs.com/likwo/p/3641135.html) Android 通过Socket 和服务器通讯,是一种比较常用的通讯方式,时间比较紧,说下大 ...