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、1,2位置交换,3,4位置交换,...,n-1,n位置交换
现在问执行了q次操作之后序列是什么,每次操作可以是两种操作的任意一种
题解:
我们把数列按位置的奇偶分为两堆,无论哪种操作,始终都还是这两堆,最多就是整堆的对换和一个堆内部的偏移。
所以我们只要记录第一个位置和第二个位置的数的变化(相当于每一堆的第一个数),那么后面的数都可以递推出来。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = 1e6 + ;
int arr[maxn]; int main() {
int n, q;
scanf("%d%d", &n, &q);
int a = , b = ;
for (int i = ; i < q; i++) {
int cmd;
scanf("%d", &cmd);
if (cmd == ) {
int v; scanf("%d", &v);
int p = ((-v) % n + n) % n + ;
int t1, t2;
if (p % ) {
t1 = (a + p - - + n) % n + ;
t2 = (b + p - - + n) % n + ;
}
else {
t1 = (b + p - - + n) % n + ;
t2 = (a + p - ) % n + ;
}
a = t1; b = t2;
}
else {
swap(a, b);
}
}
arr[] = a, arr[] = b;
for (int i = ; i <= n; i++) {
arr[i] = (arr[i - ] + ) % n + ;
}
for (int i = ; i < n; i++) printf("%d ", arr[i]);
printf("%d\n", arr[n]);
return ;
}
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) 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 Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟
C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
- Codeforces Round #348(VK Cup 2016 - Round 2)
A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- DWZ 验证 CLASS 规则
验证:格式 class="XXXX" 即可验证. required: "必填字段", remote: "请修正该字段", email ...
- 如何使用10个小时搭建出个人域名而又Geek的独立博客?
1.安装准备软件 Node.js.Git.GitHub DeskTop(前两个必须安装,后者可选) 2.本地搭建hexo框架.配置主题.修改参数.实现本地测试预览 3.链接GitHub.实现在线预览 ...
- WIN7实用的运行命令
运行命令主要是DOS操作系统的运行方式.为方便用户的操作,微软公司将一些常用的命令,如DIR,CD等命令全部集成在系统里面:存放这些内部命令的文件是“Command”(文件后缀.com).它与IO.s ...
- Spring中Quartz的配置
Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz,下面就看看在Spring中怎样配置Quartz: 首先,来写一个测试被调度的类:(QuartzHelloWorldJ ...
- 网站添加到IIS和附件进程调试(新手使用篇)
一.网站添加到IIS 做网站开发,很有必要把项目添加到IIS中,这对浏览和后期的调试很有帮助.怎么把网站添加到IIS上? 1). 打开IIS,然后操作步骤如下图: 选择Default Web Site ...
- 7款外观迷人的HTML5/CSS3 3D按钮特效
1.CSS3超酷3D弹性按钮 按钮实现非常简单 今天我又要向大家分享一款实现超级简单的CSS3 3D弹性按钮,它在鼠标按下时不仅从视觉上感受到3D立体的效果,而且更有弹性的动画特效,非常可爱. 在线演 ...
- some windowsphone templates
http://inspirationfeed.com/freebies/20-free-windows-phone-7-mockup-and-wireframing-resources/
- 使用HttpWebRequest以及HttpWebResponse读取Http远程文件
主页>杂项技术>.NET(C#)> 使用HttpWebRequest以及HttpWebResponse读取Http远程文件 jackyhwei 发布于 2010-08-15 21: ...
- DIV_ROUND_UP(x,y)实现x/y向上取整
#define DIV_ROUND_UP(x,y) (((x) + ((y) - 1)) / (y)) 1.问题 x.y都是整数,且x > 1, y > 1,求 x / y的向上取整,即: ...
- 用泛型的IEqualityComparer<T>接口去重复项
提供者:porschev 题目:下列数据放在一个List中,当ID和Name都相同时,去掉重复数据 ID Name 1 张三 1 李三 1 小伟 1 李三 2 李四 2 李武 ----- ...