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 ...
随机推荐
- ruby(html)
有的时候,我们要给汉字标记拼音,让拼音显示要汉字的上面 <ruby>中国人<rp>(</rp><rt>zhong guo ren</rt>& ...
- Android webkit 事件传递流程详解
前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...
- mysql一对多关联查询的时候筛选条件
mysql实现users 表和 logoin_log表是一对多, 现在是把user的信息找出来 关联上一些 logoin_log表的数据, 因为a表是多的一方,要多他的数据进行一些条件匹配,这个sql ...
- web.config connectionStrings 数据库连接字符串的解释
先来看一下默认的连接SQL Server数据库配置<connectionStrings> <add name="LocalSqlServer" connect ...
- Cocos2d-JS动画
与动作密不可分的还有动画,动画又可以分为场景过渡动画和帧动画.场景过渡动画我们在以往介绍过,这一个我们只介绍帧动画.帧动画帧动画就是按一定时间间隔.一定的顺序.一帧一帧地显示帧图片.我们的美工要为精灵 ...
- UI3_UICollectionViewMuti
// AppDelegate.m // UI3_UICollectionViewMuti // // Created by zhangxueming on 15/7/16. // Copyright ...
- hdu 3665 Seaside floyd+超级汇点
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3665 题意分析:以0为起点,求到Sea的最短路径. 所以可以N为超级汇点,使用floyd求0到N的最短 ...
- Linux操作杂记
centos7修改默认运行等级 查看当前默认运行等级: systemctl get-dafault 修改默认运行等级为5: systemctl set-default graphical.target ...
- 如何设置SecureCRT通过代理连接SSH[转]
http://blog.didu.me/article/84 公司限制了连接外网的端口和IP,只能通过proxy 连接.刚配置了一下 secureCRT 连接外网,貌似速度还是不错,写出来共享下. 如 ...
- JavaScript 中的 replace 方法
定义和用法 replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. stringObject.replace(regexp/substr,replaceme ...