H.Shifting
Description
John Doe has found the beautiful permutation formula.
Let's take permutation p = p1, p2, ..., pn. Let's define transformation f of this permutation:
where k(k > 1) is an integer, the transformation parameter, r is such maximum integer that rk ≤ n. If rk = n, then elements prk + 1, prk + 2 and so on are omitted. In other words, the described transformation of permutation p cyclically shifts to the left each consecutive block of length k and the last block with the length equal to the remainder after dividing n by k.
John Doe thinks that permutation f(f( ... f(p = [1, 2, ..., n], 2) ... , n - 1), n) is beautiful. Unfortunately, he cannot quickly find the beautiful permutation he's interested in. That's why he asked you to help him.
Your task is to find a beautiful permutation for the given n. For clarifications, see the notes to the third sample.
Input
A single line contains integer n (2 ≤ n ≤ 106).
Output
Print n distinct space-separated integers from 1 to n — a beautiful permutation of size n.
Sample Input
2
2 1
3
1 3 2
4
4 2 3 1
Hint
A note to the third test sample:
- f([1, 2, 3, 4], 2) = [2, 1, 4, 3]
- f([2, 1, 4, 3], 3) = [1, 4, 2, 3]
- f([1, 4, 2, 3], 4) = [4, 2, 3, 1]
/***************************************************************************************/
模拟水过,STL一直都很好用,这次正好deque派上用场,具体上代码
#pragma comment (linker,"/stack:102400000,102400000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<iostream>
#include<string>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
const double PI=acos(-1.0);
#define eps 1e-8
#define inf 1000000000
#define fib 112233
#define ll __int64
#define able puts("0000000000000000000000")
template<class T_T> T_T f_max(T_T a,T_T b) { return a>b?a:b; }
template<class T_T> T_T f_min(T_T a,T_T b) { return a<b?a:b; }
template<class T_T> T_T f_abs(T_T a) { return a>0?a:-a; }
template<class T_T> T_T gcd(T_T a,T_T b){ return b?gcd(b,a%b):a; }
template<class T_T> void swap(T_T *a,T_T *b){T_T c;c=a;a=b;b=c;}
int main()
{int i,n,m;deque<int> d;scanf("%d",&n);for(i=1;i<=n;i++)d.push_back(i);for(i=2;i<=n;i++){m=(n-1)/i*i;d.push_back(d[m]);for(;m-i>=0;m-=i)d[m]=d[m-i];d.pop_front();}for(i=0;i<n;i++)printf("%d ",d[i]);printf("\n");return 0;
}
H.Shifting相关推荐
- H - Shifting Sort
思路: 开两个数组,其中一个没有排序的,另一个是未排序的, 首先把第一个最小值元素放到最前面,然后只关注怎么把剩下元素的最小值移动到前面,不关注其他元素发生了什么变化. 选择排序依次把最小值放到前面, ...
- Codeforces Round #703 (Div. 2)A. Shifting Stacks
A. Shifting Stacks time limit per test1 second memory limit per test256 megabytes inputstandard inpu ...
- Shifting Stacks【题解】
Codeforces Round #703 (Div. 2)A. Shifting Stacks## 问题描述: A. Shifting Stacks time limit per test1 sec ...
- 相位测量轮廓术Phase Measurement Profilometry(PMP)+相移方法Phase Shifting Method
之前写了傅里叶变换轮廓术FTP三维重建的方法,那接下来就简单写一下相位测量轮廓术PMP,下面也都直接简称为PMP. 因为PMP用的是相移方法(phase shifting method),所以有很多文 ...
- Linux df -h 显示磁盘空间满,但实际未占用满——问题分析
问题现象 工作中遇到一个问题,在 TX2 系统上,告警提示磁盘空间不够,如图所示 wohu@wohu:/$ df -h Filesystem Size Used Avail Use% Mounted ...
- Linux实现ffmpeg H.265视频编码
Linux实现ffmpeg H.265视频编码 几乎所有观看的视频,数字地面电视,电缆,卫星或互联网上的压缩.原始的,未压缩的视频太大,会浪费太多的带宽.在DVD和Blu-ray之前,有视频CD(VC ...
- H.264 Video Codec速度和质量
H.264 Video Codec速度和质量 从Kepler开始的所有 NVIDIA GPUs 都支持完全加速的硬件视频编码: GPUs 从费米开始支持完全加速的硬件视频解码.最近发布的图灵硬件提供了 ...
- H.265 HD 和H.265 4K Video Encoder IP Core
H.265 HD 和H.265 4K Video Encoder IP Core H.265 HD Video Encoder IP Core(H.265 HD Video/Audio Encoder ...
- H.265视频编码与技术全析(下)
H.265视频编码与技术全析(下) 四.帧内预测模式 共35个(h264有9个),包括Planar,DC,33个方向模式: 除了Intra_Angular预测外,HEVC还和H.264/MPEG-4 ...
最新文章
- 心得丨机器学习自学指南(覆盖各个阶段的心得体会哦)
- Ubuntu下安装node和npm
- 数据压缩 第四次作业
- 前端学习(2185):tabberitem传入active图片
- Integer缓存池
- 怎样学好python编程-一个新手,什么编程都没学过怎么学好Python?
- lambda表达式_C++11的lambda表达式递归
- 迎建国七十周年,Linux厂商巡礼之优麒麟
- 项目开发计划——机房收费系统
- Servlet容器与Servlet的关系
- 运动会加油稿计算机学院150字,学校运动会加油稿150字10篇
- Stata Journal 2001-2019年全部期刊目录及下载链接
- 解决IDEA SSM项目sql文件打开提示No data sources are configured to run this SQL and provide advanced code ass的问题
- 网站服务器登录很慢,网站打开速度慢如何解决?有何技巧?
- 树莓派+android+盒子,树莓派3安装Android TV系统图文教程
- QColor类的使用
- Telnet操作步骤
- Swift不深入只浅出入门教程-孟祥月-专题视频课程
- 电机世界之直流有刷电机(科普文)
- SQL注入攻击及防御 手动注入+sqlmap自动化注入实战(网络安全学习12)
热门文章
- Face Recognition using Gabor Filters
- Unity3D Editor 编辑器扩展2 选取物体、撤销操作和窗口小部件的显示
- oracle数据库日志记录内容,oracle日志记录方式
- 搭建Swagger框架时,浏览不到Swashbuckle.AspNetCore包的简单解决办法
- 允许Traceroute探测漏洞解决方法
- 百度、搜狗、讯飞同时宣布语音识别准确率达到97%,他们是怎么做到的?
- [附源码]java毕业设计医院门诊信息管理系统
- 硬盘基本术语(磁道、扇区、柱面、磁头数、簇)
- 国内访问github
- MySQL 数据库 1129错误