https://codeforces.com/contest/1157/problem/C1

题意:给一个不重复的元素的数组,每次可以在头或者尾取一个数,求取数最长严格递增序列的方法

题解:因为元素不重复,每次选大于上一个值,而且绝对值相对较小的

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
string ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);//scanf("%d",&t);//while(t--){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);l=1;r=n;int now=0;while(l<=r){bool u=a[l]>now;bool v=a[r]>now;if(u&&v){if(a[l]-now<a[r]-now){ans+='L';now=a[l++];}else{ans+='R';now=a[r--];}}else if(u||v){if(u){ans+='L';now=a[l++];}else{ans+='R';now=a[r--];}}else{break;}}cout<<ans.size()<<endl;cout<<ans<<endl;//}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Increasing Subsequence (easy version)相关推荐

  1. Codeforces Round #555 (Div. 3), problem: (C2) Increasing Subsequence (hard version)【贪心+撞到南墙也不回头】

    题目链接 题目大意 复杂版大意是我们可以从左右两端每次拿走一个数,一直拿,不过要满足一个条件,每次拿的数要保证严格递增(即从小到大然后不会有相同的情况) 复杂版的话是会有相同的数字出现 在题解中正式说 ...

  2. Increasing Subsequence (hard version)

    https://codeforces.com/contest/1157/problem/C2 题意:给一个存在重复的元素的数组,每次可以在头或者尾取一个数,求取数最长严格递增序列的方法 题解:因为如果 ...

  3. Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)

    题目链接:http://codeforces.com/contest/1157/problem/C2 当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列 #include <iostr ...

  4. D1. Kirk and a Binary String (easy version)

    题目链接:http://codeforces.com/contest/1204/problem/D1 D1. Kirk and a Binary String (easy version) time ...

  5. HPU第三次积分赛-D:Longest Increasing Subsequence(DP)

    Longest Increasing Subsequence 描述 给出一组长度为n的序列,a1​,a2​,a3​,a4​...an​, 求出这个序列长度为k的严格递增子序列的个数 输入 第一行输入T ...

  6. [Swift]LeetCode673. 最长递增子序列的个数 | Number of Longest Increasing Subsequence

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  7. The Longest Increasing Subsequence (LIS)

    传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...

  8. 674 Longest Continuous Increasing Subsequence(每日一题)

    674:Longest Continuous Increasing Subsequence 每日一题的第一天 解题思路 双重循环 class Solution {public int findLeng ...

  9. C++longest increasing subsequence 最长递增子序列的实现之二(附完整源码)

    C++longest increasing subsequence 最长递增子序列的实现 C++longest increasing subsequence 最长递增子序列的的实现完整源码(定义,实现 ...

最新文章

  1. bitset优化+滚动优化dp ----- 2021牛客多校第8场 F Robot
  2. 集群四 mysql-5.7.16一键安装
  3. IDEA中报错spring-boot-maven-plugin:not found
  4. 服务间调用要通过网关吗_Asp.Net Boilerplate微服务实战(二)架构解析
  5. Spark DataFrame----一个用于大规模数据科学的API
  6. 计算机刷帖知识点,09计算机408分(沙滩帖)
  7. 公共平台服务治理与鉴权
  8. c++全局类对象_C++ 类在内存中的存储方式(一)
  9. ruby hash方法_Ruby中带有示例的Hash.rassoc(obj)方法
  10. mui PopPicker面板关闭后的回调函数
  11. ViewPager 简单实现左右无限滑动.
  12. python实现PDF文件合并成一个文件
  13. 虚拟机Windows xp联网
  14. Simulink代码生成应用教程
  15. (精华2020年5月12日更新) vue实战篇 axio.js封装和环境配置
  16. 使用Bugly 作为APP异常上报工具
  17. Hibernate4.3.1搭建Log4J日志环境
  18. 一看就懂→专票电子化的三条实现路径
  19. 卡迪夫大数据专业排名_2019QS排名出炉啦!看看卡迪夫大学那些世界前百强的学科...
  20. 风控标签体系的使用与介绍

热门文章

  1. 语音怎么进入滤波器matlab,基于Matlab的语音信号滤波器的设计与实现
  2. 二叉树路径和最大python_python3实现在二叉树中找出和为某一值的所有路径(推荐)...
  3. 304 vue 启动项目打开页面_Vue搭建项目工程(续)
  4. mysql怎么使用sql语句查看表的编码_MySQL中使用SQL语句查看某个表的编码
  5. css中哪些属性与创建多列相关,css3中的新增属性有哪些
  6. java变量访问权限_JAVA成员变量的访问权限
  7. python在sql添加数据库_使用Python创建MySQL数据库实现字段动态增加以及动态的插入数据...
  8. 浅拷贝 python_python中什么是浅拷贝
  9. 下载Java Jar包的网站(托管厂库)
  10. 【数据分析实例】1000 万条淘宝用户行为数据实时分析