当前位置:网站首页>(牛客多校二)G-Link with Monotonic Subsequence(构造题)
(牛客多校二)G-Link with Monotonic Subsequence(构造题)
2022-07-25 05:43:00 【AC__dream】
题目:
样例输入:
3
1
2
3样例输出:
1
1 2
1 3 2题意:给定一个n,然后输出一个n的全排列p使得其max(lis(p),lds(p))最小。
分析:
这种题目我是通过打表发现的规律,就是说对于一个长度为n的全排列,那么max(lis(p),lds(p))的最小值是sqrt(n)的上取整,这是对一些n试探得到的,然后尝试构造发现我们可以先对n个数进行从小到大分块,每块大小为sqrt(n)的上取整,然后我们直接把一个块内的数连续输出即可,先输出块内数字比较大的块,比如长度为9的全排列,我们直接输出7,8,9,4,5,6,1,2,3
这种题的做题技巧就是先打表找一下规律,然后跟着规律尝试去构造
下面是代码:
#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;
}
边栏推荐
- R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
- 50 places are limited to open | with the news of oceanbase's annual press conference coming!
- 聊聊 Redis 是如何进行请求处理
- Big talk · book sharing | Haas Internet of things device cloud integrated development framework
- Leetcode 15: sum of three numbers
- 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
- CSDN编程挑战赛之数组编程问题
- HTB-Devel
- 动态规划学习笔记
猜你喜欢

50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)

HTB-Arctic

10、渲染基础

Adaptation dynamics | in June, sequoiadb completed mutual certification with five products

Microservice gateway component

Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions

微服务 - 配置中心 - Nacos

Game 302 of leetcode

C100: smallest hevc visual IOT MCU

Mechanism and principle of multihead attention and masked attention
随机推荐
For data security reasons, the Dutch Ministry of Education asked schools to suspend the use of Chrome browser
R language data The table package performs aggregation transforms of data packets and calculates the grouping interquartile range (IQR) of dataframe data
暑期总结2
background
Mechanism and principle of multihead attention and masked attention
Microservice - hystrix fuse
sqlilabs less-28~less-8a
An SQL execution process
剑指 Offer 05. 替换空格
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
Matlab drawing example: 5: Biaxial graph
Easyrecovery free data recovery tool is easy to operate and restore data with one click
剖析kubernetes集群内部DNS解析原理
Typera+picgo+ Alibaba cloud OSS setup and error reporting solution [reprint]
Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions
HTB-Beep
ThreadLocal
C编程 --“最大子数组的和” 的动态规划的解法
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Unity接入ChartAndGraph图表插件