CodeForces - 1017 C. The Phone Number(数学)
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.
The only line contains one integer nn (1≤n≤1051≤n≤105) — the length of permutation that you need to build.
Print a permutation that gives a minimum sum of lengths of LIS and LDS.
If there are multiple answers, print any.
4
3 4 1 2
2
2 1
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.
题意:给定N,输出一个N的排列,满足其LIS+LDS最小。
思路:当时猜到了是根号倒序排序,但是写WA了。 应该是有什么证明的,不过不难想。
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int N,tN,i,j;
scanf("%d",&N); tN=sqrt(N); int p=N;
for(i=;i<=N;i+=tN){
for(j=min(N,i+tN-);j>=i;j--) a[j]=p--;
}
for(i=;i<=N;i++) printf("%d ",a[i]);
return ;
}
CodeForces - 1017 C. The Phone Number(数学)的更多相关文章
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- Codeforces Gym 100425A Luggage Distribution 二分 数学
A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...
- 【 CodeForces - 392C】 Yet Another Number Sequence (二项式展开+矩阵加速)
Yet Another Number Sequence Description Everyone knows what the Fibonacci sequence is. This sequence ...
- CodeForces 546 D. Soldier and Number Game(素数有关)
Description Two soldiers are playing a game. At the beginning first of them chooses a positive integ ...
- Codeforces 839D Winter is here【数学:容斥原理】
D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard i ...
- A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】
题目: Little C loves number «3» very much. He loves all things about it. Now he has a positive integer ...
- 【codeforces 514A】Chewbaсca and Number
[题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...
- HDU 1018 Big Number 数学题解
Problem Description In many applications very large integers numbers are required. Some of these app ...
随机推荐
- java.sql.SQLException: 无法转换为内部表示 -〉java 查询oracle数据库返回错误信息
java.sql.SQLException: 无法转换为内部表示 Query: SELECT * FROM nontheasttycoon Parameters: [] at org.apac ...
- 【BZOJ4205】卡牌配对 最大流
[BZOJ4205]卡牌配对 Description 现在有一种卡牌游戏,每张卡牌上有三个属性值:A,B,C.把卡牌分为X,Y两类,分别有n1,n2张. 两张卡牌能够配对,当且仅当,存在至多一项属性值 ...
- full stack on the road
Full Stack, I'm coming. 有人说全栈只是个理想情况,但我不这么认为,因为好多思想是想通的, 比如 OO.函数式编程.设计模式... 也有人说搞全栈的人样样普通,可是为嘛我在学习j ...
- Java程序发送邮件
之前上网有看到过别人总结的使用java程序发送邮件,于是自己下来练习,把自己学习的一些心得总结出来. 首先我们这里需要采用两个jar包: 需要的朋友可以自行上网去CSDN类似的网站上面找 顺便把自己测 ...
- 函数创建XML文件
REPORT YTST_XML_14. *----------------------------------------------------------------------* * PANT ...
- matlab + c/c++ opencv 混合编程
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- Python: generator, yield, yield from 详解
1.Generator Expressions 生成器表达式是用小括号表示的简单生成器标记法: generator_expression ::= "(" expression co ...
- php自定义的格式化时间示例代码
时间刚好是5分钟前,则对应的时间戳就会被格式化为5分钟前,自定义的格式化时间方法如下,感兴趣的朋友可以参考下 如:时间刚好是5分钟前,则对应的时间戳就会被格式化为5分钟前,不多说了,直接贴上代码: 复 ...
- iBatis 简单介绍及基础入门
iBATIS一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2002年发起的开放源代码项目.于2010年6月16号被谷歌托管,改名为MyBatis.是一个基 ...
- C#调用大漠插件
大漠插件是一个很不错的东西,在按键精灵和易语言里面用得很多,可以后台找图找字,写游戏自动脚本用得特别多.前面写一个微信的自动脚本,查了一些资料,易语言不太熟悉,按键精灵功能上可能不好实现,就找了些资料 ...