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. javascript 自定义发布与订阅

    //声明一个类,与普通的类的声明不一样, function Girl() { //将类的事件声明成一个私有的属性,里面是一个对象 this._events = {} } /* { "失恋&q ...

  2. [转] 前端开发利器--Brackets 的七种武器和旁门左道

    转自:http://www.jianshu.com/p/ff7798aa4548 Brackets是Adobe开发的web编辑器,是一款免费开源.多平台支持的软件,并在于GitHub上维护.Brack ...

  3. eclipse 列编辑

    ALT + SHIFT +A 进入列编辑模式,可以一次性操作多行列. 再次按住 ALT + SHIFT +A 则退出列编辑模式.

  4. npm命令 VS yarn命令

    npm yarn 说明 npm init yarn init  在项目中引导创建一个package.json文件 npm install yarn install/yarn  安装所有依赖包(依据pa ...

  5. 4、shader透明测试(AlphaTest)

    主要用于花草树木 用3D的Plane来实现透明的例子: 给Plane先赋予一个带alpha通道的透明图片,但是此图片此时是看不出来是透明的,如下: 现在我们要做的就是显示透明的效果:现在就用到了alp ...

  6. Java实现网页截屏功能(基于phantomJs)

    公司最近有个需求:把用户第一次的测量身体信息和最近一次测量信息进行对比,并且需要把对比的数据截成图片可以发给用户(需要在不打开网页的情况下实时对网页进行截图然后保存到服务器上,返回图片地址),通过网上 ...

  7. Python-爬取"我去图书馆"座位编码

    原文地址:http://fanjiajia.cn/2018/11/22/Python-%E7%88%AC%E5%8F%96%E2%80%9D%E6%88%91%E5%8E%BB%E5%9B%BE%E4 ...

  8. 【bzoj1176】[Balkan2007]Mokia/【bzoj2683】简单题 CDQ分治+树状数组

    bzoj1176 题目描述 维护一个W*W的矩阵,初始值均为S(题目描述有误,这里的S没有任何作用!).每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数 ...

  9. python数据绘图常用方法总结

    挖坑,以后还会更新吧 做数学建模画图使用了matplotlib和numpy,这里简单总结一下常用的用法 一.数据拟合 1.np.polyfit(x, y, n) 使用n次多项式去拟合x,y散点图,返回 ...

  10. Codeforces 821E Okabe and El Psy Kongroo(矩阵快速幂)

    E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...