当前位置:网站首页>(Niuke multi School II) G-LINK with monotonic subsequence (construction question)
(Niuke multi School II) G-LINK with monotonic subsequence (construction question)
2022-07-25 05:45:00 【AC__ dream】
subject :
The sample input :
3
1
2
3Sample output :
1
1 2
1 3 2The question : Given a n, Then output a n The whole arrangement p Make it max(lis(p),lds(p)) Minimum .
analysis :
I found the rule of this problem by typing a table , That is to say For a length of n The whole arrangement , that max(lis(p),lds(p)) The minimum value of is sqrt(n) Take the whole of , This is right for some n I got it by trial , Then we try to construct and find that we can do it first n The number is divided into blocks from small to large , The size of each piece is sqrt(n) Take the whole of , Then we can directly output the numbers in a block continuously , First output the block with large number in the block , For example, the length is 9 The whole arrangement , We export it directly 7,8,9,4,5,6,1,2,3
The skill of this kind of question is to find the rule by typing the table first , Then try to construct according to the law
Here is the code :
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<vector>
using namespace std;
const int N=1e6+10;
vector<int>p[N];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
scanf("%d",&n);
int t=(int)sqrt(n-1)+1;
int cnt=1,tt=1;
p[1].clear();
for(int i=1;i<=n;i++)
{
if(cnt>t) cnt=1,p[++tt].clear();
cnt++;
p[tt].push_back(i);
}
for(int i=tt;i>=1;i--)
for(int j=0;j<p[i].size();j++)
printf("%d ",p[i][j]);
puts("");
}
return 0;
}
边栏推荐
- sqlilabs less-28~less-8a
- (14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动
- 聊聊 Redis 是如何进行请求处理
- C Programming -- the solution of dynamic programming of "the sum of the largest subarray"
- Microservice - remote invocation (feign component)
- Leetcode 204. count prime numbers (wonderful)
- Leetcode 202. 快乐数(一点都不快乐)
- sqlilabs less-29
- ABC 261.D - Flipping and Bonus ( DP )
- 对于von Mises distribution(冯·米塞斯分布)的一点心得
猜你喜欢

10、渲染基础

Easyrecovery free data recovery tool is easy to operate and restore data with one click

easyrecovery免费数据恢复工具操作简单一键恢复数据
![50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int](/img/1b/b8529b6f1d163a9e5d5dad2b78ce93.png)
50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int

An SQL execution process

SystemVerilog中interface(接口)介绍

Leetcode 202. happy number (not happy at all)

Unity接入ChartAndGraph图表插件

Please stop using system The currenttimemillis() statistical code is time-consuming, which is really too low!

(2022牛客多校)D-Link with Game Glitch(spfa)
随机推荐
R language uses wilcox.test function to perform Wilcox signed rank test to obtain confidence interval of population median (set conf.level parameter to specify confidence level and size of confidence
ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
Array programming problem of CSDN programming challenge
The difference between $write and $display in SystemVerilog
Automatic usage in SystemVerilog
2020icpc Jiangxi warm up e.robot sends red packets (DFS)
sqlilabs less-28~less-8a
sqlilabs less-29
R language uses data.table function to create data.table data (use: operator to create continuous numeric vector)
QT qtextedit setting qscrollbar style sheet does not take effect solution
(15)[驱动开发]过写拷贝
50 places are limited to open | with the news of oceanbase's annual press conference coming!
Equal proportion of R language test group: use the prop.test function to test whether the success proportion of the two groups is equal
background
Big talk · book sharing | Haas Internet of things device cloud integrated development framework
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
HTB-Arctic
Vim配置Golang开发环境
VPP cannot load up status interface
Microservice gateway component