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 ...
随机推荐
- OSPF路由汇总和默认路由设置
目标 掌握OSPF路由汇总的配置 掌握OSPF默认路由的配置 一.——区域间汇总 配置IP,R2四个环回口 R1(config)#inter s1/0 R1(config-if)#ip add 200 ...
- JavaScript之Function函数深入总结
整理了JavaScript中函数Function的各种,感觉函数就是一大对象啊,各种知识点都能牵扯进来,不单单是 Function 这个本身原生的引用类型的各种用法,还包含执行环境,作用域,闭包,上下 ...
- 安装Apache(httpd服务)
安装Apache(httpd服务) ① 移动所有压缩包到root文件夹下(root的家) ② 解压httpd压缩包(.tar.gz) 使用tar指令解压.tar.gz压缩包 tar 指令 -zxf : ...
- windows通过thrift访问hdfs
thirift是一个支持跨种语言的远程调用框架,通过thrift远程调用框架,结合hadoop1.x中的thriftfs,编写了一个针对hadoop2.x的thriftfs,供外部程序调用. 1.准备 ...
- 转:12种JavaScript MVC框架之比较
Gordon L. Hempton是西雅图的一位黑客和设计师,他花费了几个月的时间研究和比较了12种流行的JavaScript MVC框架,并在博客中总结了每种框架的优缺点,最终的结果是,Ember. ...
- JQGrid+Webservice+LINQ
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jqgridtest.asp ...
- OpenSUSE 安装并启动Tomcat
安装.用YsST2搜索tomcat安装就好了.不过版本肯定不如官网的新,笔者用的是7.0.42,最新的已经到8.X了. 启动.在服务管理器中找到tomcat,启动.
- Apache 的 Rewrite 规则详细介绍
Rewrite标志: R[=code](force redirect) 强制外部重定向 F(force URL to be forbidden) 禁用URL,返回403HTTP状态码 G(force ...
- 提高Linux安全性--hosts.allow, hosts.deny 文件修改方法
有一种办法来提高Linux安全性--修改 hosts.allow , hosts.deny 这2个文件来配置 允许某个ip访问, 或者禁止访问. 可以通过这种方式设置限制 sshd 的远程访问, 只允 ...
- js IDE WebStorm 注册码
webStorm : UserName:William ===== LICENSE BEGIN ===== 45550-12042010 00001SzFN0n1bPII7FnAxnt0DDOPJA ...