I - Increasing and Decreasing
阿新 • • 發佈:2020-08-16
https://vjudge.net/contest/388843#problem/I
Notice:Don't output extra spaces at the end of one line.Givenn,x,yn,x,y, please construct a permutation of lengthnn, satisfying that:
- The length of LIS(Longest Increasing Subsequence) is equal toxx.
- The length of LDS(Longest Decreasing Subsequence) is equal to
If there are multiple possible permutations satisfying all the conditions, print the lexicographically minimum one.
InputThe first line contains an integerT(1≤T≤100)T(1≤T≤100), indicating the number of test cases.
Each test case contains one line, which contains three integersn,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 containsnnintegers, 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; }