您的位置:首页 > 其它

GYM 100488 Construct a Permutation(构造|想法)

2017-09-08 19:41 309 查看

题目链接

题意

给出a和b,让你构造出来最长的、且最长上升子序列长度为a,最长下降子序列长度为b的序列。

这个题我们没有想出来要怎么构造 ,还停留在这个最大长度是不是a+b(b等于1的时候是a)的阶段

解决

思路是创建b组长度为a的上升子序列,而且每一组的最大值都比前一组的最小值来的小,则必然满足题意

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6;
void open()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
}
//思路是创建b组长度为a的上升子序列,而且每一组的最大值都比前一组的最小值来的小,则必然满足题意
int main()
{
int a,b;
int num[300000];
while(~scanf("%d%d",&a,&b))
{
int tot=a*b;
printf("%d\n",tot);
int i,j,k;
for(i=1;i<=b;i++)       //共创建b组连续上升的子序列,正在创建第i个序列
{
for(j=i*a,k=tot-(i-1)*a;j>(i-1)*a;j--)    //a是长度,k为当前要填充的数字
{
num[j]=k;
k--;
}
}
printf("%d",num[1]);
rep(i,2,tot+1) printf(" %d",num[i]);
puts("");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: