GYM 100488 Construct a Permutation(构造|想法)
来源:互联网 发布:无锡软件研究所 编辑:程序博客网 时间:2024/06/05 08:15
题目链接
题意
给出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(""); }}
阅读全文
0 0
- GYM 100488 Construct a Permutation(构造|想法)
- GYM 100488 M.Construct a Permutation(构造)
- GYM 100488 Two Pirates(想法)
- CodeForces 303 A.Lucky Permutation Triple(构造)
- UVa 11129 An antiarithmetic permutation (构造题&想法题&分治)
- Codeforces 482A Diverse Permutation(构造)
- codeforces #303A Lucky Permutation Triple 构造
- GYM 100488 B.Impossible to Guess(构造)
- GYM 100488 J.Hyperdromes Strike Back(构造)
- codeforces 123A A. Prime Permutation(数论+构造)
- fzu1911 (Construct a Matrix) 矩阵快速幂+构造
- FZU 1911 Construct a Matrix(矩阵快速幂+构造)
- Gym 100803A(贪心)
- GYM 100488 E.Just Change a Word(水~)
- GYM 101149 M.Ex Machina(构造)
- GYM 101173 K.Key Knocking(构造)
- GYM 101173 L.Lost Logic(构造)
- Codeforces Gym 101142 J. Java2016 (构造)
- CSS3图片翻转切换案例及其中重要属性解析 (赞)
- Spring初学小笔记1《2017-09-08》
- 【64位】centos7+jdk+mysql+tomcat配置
- hd--1114 存钱罐
- 1665:完美覆盖(4.5算法之动态规划)
- GYM 100488 Construct a Permutation(构造|想法)
- 3376: [Usaco2004 Open]Cube Stacking 方块游戏
- live555 源码分析:播放启动
- HTML省市二级联动
- http协议中 get post区别
- Linux操作系统的进程类型
- 【Ajax】传递Json对象到MVC后台解析
- softmax 导数推导
- 浅谈协方差矩阵