zoukankan      html  css  js  c++  java
  • I

    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(1T100)T(1≤T≤100), indicating the number of test cases.

    Each test case contains one line, which contains three integers n,x,y(1n105,1x,yn)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;
    }
    

      

  • 相关阅读:
    python多线程编程(6): 队列同步
    Python验证Url地址的正则表达式
    centos下redis安全配置相关
    redis
    mysql安装 配置
    centos7安装python3 环境变量配置 django安装 以及tab补全功能
    saltstack 与常用服务部署
    vim
    Linux系统基础优化及常用命令
    Shell 基本命令
  • 原文地址:https://www.cnblogs.com/SutsuharaYuki/p/13512548.html
Copyright © 2011-2022 走看看