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

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

题解:因为如果存在两端元素相同的情况,只能取一端,因为序列严格递增,必然不可能再取另一端的数,因此当相同时,左右分别暴力即可

/*
*@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;//cout<<l<<" "<<r<<endl;if(u&&v){if(a[l]<a[r]){ans+='L';now=a[l++];}else if(a[l]>a[r]){ans+='R';now=a[r--];}else{temp=ans;int tempnow=now;for(int i=l;i<=r;i++){if(a[i]>now){ans+='L';now=a[i];}else{break;}}for(int i=r;i>=l;i--){if(a[i]>tempnow){temp+='R';tempnow=a[i];}else{break;}}if(temp.size()>ans.size())swap(ans,temp);break;}}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 (hard version)相关推荐

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

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

  2. Increasing Subsequence (easy version)

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

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

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

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

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

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

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

  6. The Longest Increasing Subsequence (LIS)

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

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

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

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

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

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

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

最新文章

  1. 排序(一)归并、快排、优先队列等(图文具体解释)
  2. Dos攻击工具(ZAmbIE)
  3. TCP三次握手Render Tree页面渲染=从输入URL到页面显示的过程?
  4. springmvc十六:九大组件
  5. java堆栈句柄,深入了解JVM—内存区域
  6. 双非硕士毕业4.5年晋级鹅厂T11之葵花宝典
  7. 如何为Apache Kylin快速开发新数据源?
  8. 《.NET内存管理宝典》在京东上架销售啦!
  9. 前端学习(3265):js中undefine中3相关属性
  10. GDAL读取Shp问题解决:Unable to open EPSG support file gcs.csv
  11. php jquery 源码,最新版jQuery 2.1.0完整
  12. 大数据建设意义_大数据一体化平台打造政府智能数据库,助力智慧政务建设
  13. 初学者python笔记(类的内置属性)
  14. Linux学习之CentOS(三十二)--Linux系统服务基础
  15. 分享一个在沪深300下获得146.56%超额收益的策略
  16. 一文介绍完整:python猴子补丁python monkey patch 没听过?
  17. word插入的页眉页脚看不到问题排查
  18. 2014网易游戏实习生面试体验
  19. C语言求水仙花经典案例教程
  20. 怎么选型企业客户管理软件?看看别人是怎么做的

热门文章

  1. 工具类软件操作手册_北京数字化的金蝶云团队-北京金普蝶软件科技有限公司...
  2. 3500字的txt文件_split文件拆分与合并,看完还不会,拿头拍我
  3. 与计算机硬件相关领域,计算机硬件相关专业论文范文.doc
  4. ubuntu ssh如何连接mysql_ubuntu配置ssh连接方式
  5. python序列类型唯一的映射类型_python2.x学习笔记(8)-映射和集合类型
  6. android 许可协议,Android 基本控件的使用二(注册许可协议)(CheckBox)
  7. oracle 运维案例,运维注意事项及案例讲解(个人心得)
  8. 二十三、Java类中重载和重写的区别
  9. keras从入门到放弃(十二)卷积神经网络
  10. mysql与java的计算效率_java mysql数据库查询效率问题