https://vjudge.net/contest/388843#problem/I

Notice:Don't output extra spaces at the end of one line.

Given n,x,yn,x,y, please construct a permutation of length nn, satisfying that:

- The length of LIS(Longest Increasing Subsequence) is equal to xx.
- The length of LDS(Longest Decreasing Subsequence) is equal to yy.

If there are multiple possible permutations satisfying all the conditions, print the lexicographically minimum one.

InputThe first line contains an integer T(1≤T≤100)T(1≤T≤100), indicating the number of test cases.

Each test case contains one line, which contains three integers n,x,y(1≤n≤105,1≤x,y≤n)n,x,y(1≤n≤105,1≤x,y≤n).
OutputFor each test case, the first line contains ``YES'' or ``NO'', indicating if the answer exists. If the answer exists, output another line which contains nn integers, indicating the permutation.Sample Input

4
10 1 10
10 10 1
10 5 5
10 8 8

Sample Output

YES
10 9 8 7 6 5 4 3 2 1
YES
1 2 3 4 5 6 7 8 9 10
YES
1 2 3 5 4 10 9 8 7 6
NO

Sponsor

题意:

  按照字典顺序求长度为n,最长上升子序列为x,最长下降子序列为y的最小排列。

思路:

  分段

  将排列分成 x 段,

  保证前一段为单调上升序列,

  数最多的段个数为 y (即最长递减数列

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
#define debug(x) cout<<"debug:"<<#x<<" = "<<x<<endl; #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=1e6+10;
const int mod=1e9+7; vector<int> v;
int main()
{
int T = 0;
int n = 0, x = 0, y = 0;
cin >> T;
while(T--)
{
cin >> n >> x >> y;
int s = sqrt(n);
int base = n / s;
if(base * s != n)
{
base += 1;
} int tell = base + s;
if(tell <= x+y && x+y <= n+1)
{
int p = 0;
cout << "YES" <<endl;
v.clear();
int D = 0;
for(int i = 0;i<x;i++)
{
D = min(n-x+1+i , y);
p = n-D+1;
while(p <= n)
{
v.push_back(p);
p += 1;
}
n -= D;
}
p = v.size()-1;
while(p >= 0)
{
cout << v[p];
if(p)cout<<" ";
p -= 1;
}
cout <<endl;
}
else
{
cout << "NO" << endl;
}
/*
if(tell <= n+1 && tell <= x+y)
{
cout << "YES" << endl;
v.clear();
int temp = 0;
for(int i = 0;i<x;i++)
{
temp = min(n+x-i+1 , y);
for(int j = n-temp+1; j <= n; j ++)
{
v.push_back(j);
}
n -= temp;
}
int p = v.size() - 1;
for(int i = 0;i<=p;i++)
{
cout << v[p-i] <<" ";
}
}
else
{
cout << "NO" <<endl;
}
*/
} return 0;
}

  

I - Increasing and Decreasing的更多相关文章

  1. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  2. Problem I. Increasing or Decreasing MIPT-2016 Pre-Finals Workshop, Taiwan NTU Contest, Sunday, March 27, 2016

    题面: Problem I. Increasing or DecreasingInput file: standard inputOutput file: standard outputTime li ...

  3. HDU 6852 Increasing and Decreasing 构造

    题意: 给你一个n,x,y.你需要找出来一个长度为n的序列,使得这个序列满足最长上升子序列长度为x,最长下降子序列长度为y.且这个序列中每个数字只能出现一次 且要保证最后输出的序列的字典序最小 题解: ...

  4. 20个非常棒的jQuery倒计时脚本

    使用jQuery倒计时插件可能是最简单最好的方式添加动态和交互式倒数计时器到您的网站上.我相信你已经注意到了,例如倒计时功能运行网站,显示倒计时,直到一个大事件.当网站正在维护,告诉用户什么时候回来, ...

  5. Leetcode: Sort Transformed Array

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  6. MOOCULUS微积分-2: 数列与级数学习笔记 1. Sequences

    此课程(MOOCULUS-2 "Sequences and Series")由Ohio State University于2014年在Coursera平台讲授. PDF格式教材下载 ...

  7. Moscow Pre-Finals Workshop 2016. National Taiwan U Selection

    A. As Easy As Possible 每个点往右贪心找最近的点,可以得到一棵树,然后倍增查询即可. 时间复杂度$O((n+m)\log n)$. #include <bits/stdc+ ...

  8. linux hugepage

    The intent of this file is to give a brief summary of hugetlbpage support inthe Linux kernel.  This ...

  9. Radio Basics for RFID

    Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...

  10. 2016 MIPT Pre-Finals Workshop Taiwan NTU Contest

    2016弱校联盟十一专场10.5 传送门 A. As Easy As Possible 假设固定左端点,那么每次都是贪心的匹配\(easy\)这个单词. 从\(l\)开始匹配的单词,将\(y\)的位置 ...

随机推荐

  1. ubuntu22.04使用libmysqlclient-dev,在包含mysql.h时会出现‘net_async_status’未声明

    //mysql Ver 8.0.41-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu)) //库文件是libmysqlclient-dev //在使用 g+ ...

  2. python基础—基本数据类型—数字,字符串,列表,元组,字典

    1.运算符 (1)基本运算符 +  加法   -   减法 *   乘法 /   除法 **   幂 //   取整(除法) %   取余(除法) (2)判断某个东西是否在某个东西里面包含 in no ...

  3. uni-app项目怎么实现多服务环境切换

    前情 uni-app是我比较喜欢的跨平台框架,它能开发小程序/H5/APP(安卓/iOS),重要的是对前端开发友好,自带的IDE可视化的运行和打包也让开发体验也非常棒,公司项目就是主推uni-app, ...

  4. Spring Boot 自动配置原理深度解析

    在 Spring 生态系统中,Spring Boot 自动配置是实现 "零配置" 开发的核心特性,通过约定大于配置的理念,自动为应用注入所需的基础设施配置.本文从核心注解.底层机制 ...

  5. HDFS目录配额(quota)不足导致写文件失败

    本文分享自天翼云开发者社区<HDFS目录配额(quota)不足导致写文件失败>,作者:5****m 问题背景与现象 给某目录设置quota后,往目录中写文件失败,出现如下问题"T ...

  6. git冲突的解决与版本回退遇到的问题

    这里有2个分支,master中的test.txt文件内容是master init,branch01中的test.txt文件内容是branch01 init    1.合并分支遇到冲突 在master上 ...

  7. 故障处理:Oracle一体机更换磁盘控制器后部分磁盘状态异常的案例处理

    我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效 ...

  8. 中大ACM个人赛 ABC题题解

    摸完签到题就跑了 A - Maximum Subrectangle 题意:有个C矩阵,C[i][j] = a[i]b[j], 问你在\(\displaystyle\sum_{i=x1}^{x2}\) ...

  9. ROS 简单记录(一)

    不定期更新 安装ros 依赖的包 http://wiki.ros.org/indigo/Installation/Ubuntu 可以跑通 小乌龟 http://wiki.ros.org/ROS/Tut ...

  10. PLY 模型文件简析

    PLY 模型文件简析 参考链接 wiki需要FFFQQQ TIPS 主要是一些英文的简析,但是一句话,网上讲的不清楚,特此说明 property list uchar int vertex_indic ...