[string]hdu 6852 Increasing and Decreasing

题目

[string]hdu 6852 Increasing and Decreasing_第1张图片

题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1009&cid=885

思路

先升序排列 1 2 3 4 5 6…n
要留下x个LIS即将上面的这个切割成x段进行翻转,且最长的一段长度为y
为了保证字典序最小 长度长的段尽量在后面

判断YES/NO:
在翻转最后长度为y的字符串之后,还剩长度为n-y的串,还要反转x-1段,要保证:
1<=(n-y)(x-1)<=y
即:
x+y-1<=n<=x*y

代码

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if __cplusplus >= 201103L
#include 
#include 
#endif
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;

signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,x,y;
		cin>>n>>x>>y;
		if(x+y>n+1||x*y<n) cout<<"NO"<<endl;
		else{
			cout<<"YES"<<endl;
		//	cout<<"ans:"<
			int d=INF;
			vector<int> v;
			for(int i=x;i>=1;i--){
				d=min(n-i+1,y);
			//	cout<
				for(int j=n-d+1;j<=n;j++){
					v.push_back(j);
				}
				n-=d;
			}
			for(int i=v.size()-1;i>=0;i--) cout<<v[i]<<" \n"[i==0];
		}
	}
    return 0;
}

你可能感兴趣的:([string]hdu 6852 Increasing and Decreasing)