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. 一个关于sql更新的小笔记

    一直在sqlserver下写东西,突然用mysql有些语法发生了改变,有点折腾 (MS SQL Server)语句:update A set  a.Name =   b.Name   from   A ...

  2. mysql8.0.14 安装

    1.下载 地址:https://dev.mysql.com/downloads/mysql/ 找到zip压缩文件. 2.配置环境变量 把解压后的路径配置到环境变量中 3.安装 在解压后的文件夹中新建m ...

  3. ES5新增数组方法(2):map

    通过指定函数处理数组的每个元素,并返回处理后的数组. 1.计算数组中每个元素的平方 let arr = [1, 2, 3, 4, 5, 6]; let newArr = arr.map(item =& ...

  4. URAL 1736 Chinese Hockey(网络最大流)

    Description Sergey and Denis closely followed the Chinese Football Championship, which has just come ...

  5. POJ 3860 Fruit Weights(数学+最长路径 or 最短路径)

    Description Have you ever thought about comparing the weight of fruits? That’s what you should do in ...

  6. Android Service 服务(三)—— bindService与remoteService

    (转自:http://blog.csdn.net/ithomer/article/details/7366396)   一.bindService简介 bindService是绑定Service服务, ...

  7. 软工实践Beta冲刺(1/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  8. Web-request内置对象在JSP编程中的应用

  9. Win7/8, convert dynamic disk volume to basic volume.

    之前不小心用了Win8自带的Disk Management 来调整磁盘分区的大小,当时跳出来一个warning窗口,说如果继续操作会变成dynamic disk,然后xxxx. 我心想都是Window ...

  10. BZOJ1037 ZJOI2008生日聚会(动态规划)

    设f[i][j][x][y]为安排了i个男孩j个女孩,后缀最大男孩-女孩数为x,最大女孩-男孩数为y的方案数.转移显然. #include<iostream> #include<cs ...