Codeforces 286B Shifting (看题解)
感觉这题被智力打击了。。
刚开始我想的是对于每个位置我们可以暴力找出最后的位置在哪里。
因为对于当前位置p, 在进行第x步操作时,
如果p % x == 1 则 p = p + x - 1
否则 p = p - 1
并且第一步只有nlogn次, 所以我们可以暴力找出p % x == 1的情况, 然后更新, 然后就被卡常惹。。
主要是存因子要2s钟, 卡常卡一辈子卡不过去。
其实我们发现每一步操作只有两种点, 一种p = p - 1, 另一种是 p = p + x - 1
那么我们将p = p - 1的不移动, 相当于整体往前移动一格, 改变哪些 p = p + x - 1的, 这样就可以了。。。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, a[N]; int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) a[i] = i;
int L = , R = n;
for(int i = ; i <= n; i++) {
int p = n / i * i - + L;
a[R + ] = a[p + ];
while(p - i >= ) {
a[p + ] = a[p - i + ];
p -= i;
}
L++;
R++;
}
for(int i = L; i <= R; i++) printf("%d ", a[i]);
puts("");
return ;
} /*
*/
Codeforces 286B Shifting (看题解)的更多相关文章
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- Codeforces 7E - Defining Macros 题解
目录 Codeforces 7E - Defining Macros 题解 前言 做法 程序 结尾 Codeforces 7E - Defining Macros 题解 前言 开始使用博客园了,很想写 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
随机推荐
- java程序在windows后台执行的办法
1.新建run.txt文件 2.在文件中输入一下内容: @echo off start javaw -jar xx.jar exit 3.保存,修改文件名为run.bat4.双击即可 5.删除wind ...
- Prezento – 轻量、简单的 jQuery 幻灯片插件
Prezento 是一个超级简单的 jQuery 幻灯片插件.可以让你网页以新颖的交互方式呈现.另外,Prezento 支持响应式设计,配置项也很灵活,可以根据你需要的效果配置. 您可能感兴趣的相关文 ...
- Java——Struts2 crud 简单实例(学习struts2和ssh) 用Myeclipse实现
1.new web project 2.给新建的web项目添加struts2支持 3.项目结构中有了struts.xml和struts2核心库 4.编码 4.1项目结构图 4.2源代码: (1)DbU ...
- Pytorch中的torch.cat()函数
cat是concatnate的意思:拼接,联系在一起. 先说cat( )的普通用法 如果我们有两个tensor是A和B,想把他们拼接在一起,需要如下操作: C = torch.cat( (A,B),0 ...
- 第16月第5天 performSelector afterDelay cancel dispatch_semaphore_wait
1. //不延时,可能会导致界面黑屏并卡住一会 [self performSelector:@selector(startScan) withObject:nil afterDelay:0.3]; - ...
- webstorm11.0.3连接ftp
一.工具 webstorm11.0.3 ftp工具:Beyond Compare 3 二.步骤 1.打开项目工程,按照下图中路径,打开ftp配置界面 2.在ftp配置界面 (1)右上角+号新建配置,选 ...
- img格式镜像转ISO格式
在做汇编学习时,需要用比较老的Windows XP来进行调试学习,因此找了最老的Windows XP(CN_WINXP_PRO_ISO,无SP版本 ),下载后发现镜像文件格式是img的,而virtua ...
- android AysncTask使用
1.继承AysncTask类 例子: class downloadTask extends AsyncTask<Void,Integer,Boolean> 第一个参数是传入的参数 第二个参 ...
- oracle数据库自增主键重复
select max(t.id) from T_PLAT_ENUM_VALUE tdrop sequence T_PLAT_ENUM_VALUE;create sequence T_PLAT_ENUM ...
- Visual Studio 2017中的快捷键
Ctrl+Tab: 快速切换活动文件