C. The Phone Number
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of nn can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS).

A subsequence ai1,ai2,…,aikai1,ai2,…,aik where 1≤i1<i2<…<ik≤n1≤i1<i2<…<ik≤n is called increasing if ai1<ai2<ai3<…<aikai1<ai2<ai3<…<aik. If ai1>ai2>ai3>…>aikai1>ai2>ai3>…>aik, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation [6,4,1,7,2,3,5][6,4,1,7,2,3,5], LIS of this permutation will be [1,2,3,5][1,2,3,5], so the length of LIS is equal to 44. LDS can be [6,4,1][6,4,1], [6,4,2][6,4,2], or [6,4,3][6,4,3], so the length of LDS is 33.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.

Input

The only line contains one integer nn (1≤n≤1051≤n≤105) — the length of permutation that you need to build.

Output

Print a permutation that gives a minimum sum of lengths of LIS and LDS.

If there are multiple answers, print any.

Examples
input

Copy
4
output

Copy
3 4 1 2
input

Copy
2
output

Copy
2 1
Note

In the first sample, you can build a permutation [3,4,1,2][3,4,1,2]. LIS is [3,4][3,4] (or [1,2][1,2]), so the length of LIS is equal to 22. LDS can be ony of [3,1][3,1], [4,2][4,2], [3,2][3,2], or [4,1][4,1]. The length of LDS is also equal to 22. The sum is equal to 44. Note that [3,4,1,2][3,4,1,2] is not the only permutation that is valid.

In the second sample, you can build a permutation [2,1][2,1]. LIS is [1][1] (or [2][2]), so the length of LIS is equal to 11. LDS is [2,1][2,1], so the length of LDS is equal to 22. The sum is equal to 33. Note that permutation [1,2][1,2] is also valid.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define N 100009
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
int n,a[N];
/*
分成x组,每一组y个,x*y==n,求x+y的最小值,很明显x==sqrt(n)时成立
当n%sqrt(n)==0时,令m=n/sqrt(n),即x*m==n
那么分成x组:LDS==x,每一组里的数升序,总体递减
每一组m个: LIS==m
每一组x个 :LDS=x
分成y组 : LIS=m
当n%sqrt!=0 时,就是再将剩下的放到另一组里
*/
int main()
{
scanf("%d",&n);
int index=sqrt(n);//每一组index个
int tmp=,t;
for(int i=n-index;i>=;i-=index){
t=i;
for(int j=;j<index;j++){
a[i+j]=tmp++;
}
}
for(int i=;i<t;i++) a[i]=tmp++;//剩下的再放到另一个组里
for(int i=;i<n;i++){
printf("%d%c",a[i],i==n-?'\n':' ');
}
return ;
}

cf 1017C的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

随机推荐

  1. 解释器模式和php实现

    解释器模式: 给定一个语言, 定义它的文法的一种表示,并定义一个解释器,该解释器使用该表示来解释语言中的句子. 角色: 环境角色:定义解释规则的全局信息. 抽象解释器::定义了部分解释具体实现,封装了 ...

  2. C# List的使用

    1.所需引入的命名空间: using System.Collections.Generic; 2.初始化 [1]空: List<int> list = new List<int> ...

  3. jQuery转盘插件rotate

    css .rotate{ background:#aaa; padding:100px; position: relative; } .point { position: absolute; top: ...

  4. 深入理解Java虚拟机--个人总结

    JVM内存区域 我们在编写程序时,经常会遇到OOM(out of Memory)以及内存泄漏等问题.为了避免出现这些问题,我们首先必须对JVM的内存划分有个具体的认识.JVM将内存主要划分为:方法区. ...

  5. [中文翻译] ASP.NET 5 简介(Introducing ASP.NET 5,原作ScottGu 2015/2/23)

    本文出处  [中文翻译] ASP.NET 5 简介(Introducing ASP.NET 5,原作ScottGu 2015/2/23) 这是我的文章备份 http://www.dotblogs.co ...

  6. python基础教程总结1——列表和元组

    1.序列 python含有6种内建序列——列表,元组,字符串,Unicode字符串,buffer对象,xrange对象 2.通用序列操作 2.1 索引 注:   input()根据用户输入变换相应的类 ...

  7. 重温Javascript(二)-对象

    对象 可以想象成散列表,键值对,值可以是数据或函数 创建对象的方式 1.工厂模式 function createPerson(name, age, job){ var o = new Object() ...

  8. 在DataGridView控件中隔行换色

    实现效果: 知识运用: DataGridViewRow类的公共属性DefaultCellStyle的BackColor属性 public Color BackColor {get; set;} 实现代 ...

  9. 如何使用动画库animate.css

    animate.css是一个CSS3动画库,里面预设了抖动(shake).闪烁(flash).弹跳(bounce).翻转(flip).旋转(rotateIn/rotateOut).淡入淡出(fadeI ...

  10. SQL Server 游标的应用

    ----------------SQL游标应用----------------- 今天由于业务需求,需要在存储过程中实现有一个表的主键去匹配在另一个表中作为外键所对应的数值 ,若在C#中则非常简单只需 ...