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(""); } }
相关文章推荐
- 【构造】Gym - 100781B - Bell Ringing
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(想法题,构造题)
- GYM - 100812K Might and Magic (构造字符串)
- Codeforces gym 101350F 想法
- Gym 101128H想法题
- Codeforces Gym 100342H Hard Test 构造
- [构造] Codeforces Gym 101173 CERC 16 K & BZOJ 4796 Key Knocking
- GYM 100801 H.Hash Code Hacker(构造)
- 【构造】Gym - 101411F - Figure ans Spots
- Gym 101128C想法题
- Gym - 101503I 利用到图论的构造
- GYM 101142 B.Boys and Girls(构造)
- UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
- Codeforces Gym 100425H H - Football Bets 构造
- Codeforces gym 101149 G 想法
- Codeforces Gym 101142 J. Java2016 (构造)
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
- Codeforces Gym 100203D Different vectors 想法题 + Hash
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples(构造题,想法题,好题)
- GYM 101173 K.Key Knocking(构造)