GYM 100488 M.Construct a Permutation(构造)
来源:互联网 发布:java 手动回收垃圾 编辑:程序博客网 时间:2024/06/05 05:42
Description
给出两个正整数a和b,要其构造一个序列使得该序列的最长严格上升子序列和最长严格下降子序列长度分别为a和b
Input
两个正整数a和b(1<=a,b<=500)
Output
输出合法序列
Sample Input
2 1
Sample Output
2
1 2
Solution
构造b段序列拼接一起,每段都是一个长度为a的严格上升列,且前一段最小值比后一段最大值还大,显然这是一个合法解
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 333333int ans[maxn],a,b;int main(){ while(~scanf("%d%d",&a,&b)) { printf("%d\n",a*b); for(int i=1;i<=a;i++) for(int j=i*b,k=(i-1)*b+1;j>(i-1)*b;j--,k++) ans[j]=k; for(int i=1;i<=a*b;i++) printf("%d%c",ans[i],i==a*b?'\n':' '); } return 0;}
0 0
- GYM 100488 M.Construct a Permutation(构造)
- GYM 100488 Construct a Permutation(构造|想法)
- GYM 101149 M.Ex Machina(构造)
- CodeForces 303 A.Lucky Permutation Triple(构造)
- Codeforces 482A Diverse Permutation(构造)
- codeforces #303A Lucky Permutation Triple 构造
- [gym 101149 M. Ex Machina]构造+线段树
- 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 101173 K.Key Knocking(构造)
- GYM 101173 L.Lost Logic(构造)
- Codeforces Gym 101142 J. Java2016 (构造)
- Codeforces 303A Lucky Permutation Triple 【构造 思维】
- 查找python项目依赖并生成requirements.txt
- iOS APNs 实现多语言及自定义事件
- 28款GitHub最流行的开源机器学习项目
- CODEVS 1245 最小的N个和
- 更多选项的框架容器
- GYM 100488 M.Construct a Permutation(构造)
- idea直接推送显示Push master to origin/master was rejected by remote,git命令推送 You are not allowed to push co
- 数据结构-快速排序
- 【阮一峰】TF-IDF与余弦相似性的应用(三):自动摘要
- 用arm交叉编译器编译源码包
- Bayer图像转RGB图像
- C++模板使用基础
- Spring 模块介绍
- 自学iOS开发系列----UI(视图编程入门:UIGestureRecognizer)