C. The Phone Number
time limit per test

1 second

memory limit per test

256 megabytes

 
 

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. LDScan 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.

这是一道猜规律的题。开根号分块,我这样的菜鸡自然是猜不到的。。

不过还是可以证明的,面积一定的时候,周长最小的是正方形,其实也就是基本不等式嘛。。。

所以就是如果采用分块思想,可以得知,LIS是L,LDS则为ceil(n/L),要使两者相加最小,也就是开根号的时候。

挺好的题,开阔一下思路

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 100
#define maxm 30000
#define ll long long
#define mod 1000000007
#define mem(a,b) memset(a,b,sizeof a)
#ifndef ONLINE_JUDGE
#define dbg(x) cout<<#x<<"="<<x<<endl;
#else
#define dbg(x)
#endif
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-') f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=*x+ch-'';
ch=getchar();
}
return x*f;
}
inline void Out(int a)
{
if(a>)
Out(a/);
putchar(a%+'');
}
int a[],b[];
int main()
{
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;++i) a[i]=i;
int hh=sqrt(n);
int tot=n;
int tt=n/hh;
for(int i=;i<=tt;++i)
{
for(int j=;j<=hh;++j)
{
cout<<a[tot-hh+j]<<" "; }
tot-=hh;
}
for(int i=;i<=tot;++i) cout<<a[i]<<" ";
cout<<endl;
}
}

CF502C The Phone Number的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

随机推荐

  1. Tapestry 权威讲解-备份

    http://blog.csdn.net/mindhawk/article/details/5021371#introduction

  2. java集合浅谈(一)

    一.类库结构图概览 容器对象仅能持有对象引用(对象的指针),而不是Copy对象信息,从网上搜得几张Java中集合类库的结构图,如下所示: 二.解说Collection 2.1 Collection ( ...

  3. 使用JDK的keytool生成Android签名证书

    生成证书:keytool -genkey -alias [yourapp] -keyalg RSA -validity 20000 -keystore [yourapp].keystore 输入key ...

  4. React远程服务

    http://web1.dev5.net:3002/cloud/start?server=exf2&name=zhangxiaocong http://web1.dev5.net:3002/c ...

  5. mysql insert into select 语法

    Insert into Table2(field1,field2,...) select value1,value2,... from Table1  这样就对了

  6. POJ 1015 Jury Compromise (动态规划)

    dp[i][j]代表选了i个人,D(J)-P(J)的值为j的状态下,D(J)+P(J)的最大和. #include <cstdio> #include <cstring> #i ...

  7. JavaWeb笔记(十二)日志

    日志 日志信息根据用途与记录内容的不同,分为调试日志.运行日志.异常日志等. Java常用记录日志 logger log4j log4j2 logback 其中除了logger使用的概率较小,因此主要 ...

  8. ng2 搭建本地开发环境

    git clone https://github.com/angular/quickstart.git quickstart cd quickstart npm install npm start h ...

  9. 查看ClassLoader载入了哪些类?

    在执行jar时加上-verbose:class java  -verbose:class -Xms1G -Xmx2G -jar xx.jar 必要时还可以使用 >log.txt 将输出输入到文本 ...

  10. Win10系统开启IIS服务步骤

    原文链接:http://www.111cn.net/sys/361/93003.htm