Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)
题目链接:http://codeforces.com/contest/1157/problem/C2
当左右两边数字相同时,需要判断一下取哪边能得到更长的递增序列
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <cstdio> #include <queue> #include <climits> #include <set> #include <stack> #include <string> #include <map> #include <vector> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; static const int MAX_N = 2e5 + 5; static const ll Mod = 2009; char str[MAX_N]; int a[MAX_N]; void solve(){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);int n;while(scanf("%d", &n) != EOF){for(int i = 0; i < n; ++i) scanf("%d", &a[i]);int s = 0, e = n - 1, cnt = 0, prev = 0; //prev为序列中最大值while(s <= e){if(a[s] <= prev){while(a[e] > prev && e >= s){prev = a[e--];str[cnt++] = 'R';}break;}if(a[e] <= prev){while(a[s] > prev && s <= e){prev = a[s++];str[cnt++] = 'L';}break;}if(a[s] < a[e] && a[s] > prev){prev = a[s++];str[cnt++] = 'L';continue;}if(a[s] > a[e] && a[e] > prev){prev = a[e--];str[cnt++] = 'R';continue;}int e1 = 0, e2 = 0;if(a[s] > prev){e1 = 1;while(s + e1 <= e && a[s + e1] > a[s + e1 - 1]) ++e1;}if(a[e] > prev){e2 = 1;while(e - e2 >= s && a[e - e2] > a[e - e2 + 1]) ++e2;}if(e1 > e2){prev = a[s++];str[cnt++] = 'L';}else{prev = a[e--];str[cnt++] = 'R';}}str[cnt] = '\0';printf("%d\n%s\n", cnt, str);} } int main() {solve();return 0; }
View Code
转载于:https://www.cnblogs.com/xorxor/p/10959984.html
Codeforces Round # 555 (Div. 3) C2. Increasing subsequence (complicated version) (贪心)相关推荐
- Codeforces Round #555 (Div. 3) c2 d e f
c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...
- 差分 ---- Codeforces Round #672 (Div. 2):C2. Pokémon Army (hard version)[差分的思想]
题目链接 题目大意:就算给你一序列,按照顺序出若干个数组成一个的序列,然后对这个序列定义一个权值就算奇数位置的和减去偶数位置的和,问你能的到的最大的权值是多少? **a1 - a2 + a3 - a4 ...
- Codeforces Round #672 (Div. 2) C2 - Pokémon Army (hard version)(贪心,维护变化值)
x数组里选一个子数组y(原数组顺序),y1-y2+y3-y4+- 的最大值 然后还有q次交换操作,每次修改之后都要输出新的最大值 (1)如果没有修改,单纯对于当前数组考虑,我们最后选出来的点肯定是波峰 ...
- Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version)
Codeforces Round #568 (Div. 2)C2. Exam in BerSU (hard version) 贪心+暴力 大致题意:N个人考试,每个人花费的时间是a[i],他们总共花费 ...
- Codeforces Round #636 (Div. 3) C.Alternating Subsequence
Codeforces Round #636 (Div. 3) C.Alternating Subsequence 题目链接 Recall that the sequence b is a a subs ...
- Codeforces Round #658 (Div. 1) A2. Prefix Flip (Hard Version)
Codeforces Round #658 (Div. 1) A2. Prefix Flip (Hard Version) 题目链接 There are two binary strings a an ...
- Codeforces Round #555 (Div. 3), problem: (C2) Increasing Subsequence (hard version)【贪心+撞到南墙也不回头】
题目链接 题目大意 复杂版大意是我们可以从左右两端每次拿走一个数,一直拿,不过要满足一个条件,每次拿的数要保证严格递增(即从小到大然后不会有相同的情况) 复杂版的话是会有相同的数字出现 在题解中正式说 ...
- Codeforces Round #632 (Div. 2) F. Kate and imperfection 数论 + 贪心
传送门 文章目录 题意: 思路: 题意: n≤5e5n\le5e5n≤5e5 思路: 首先有个显然的结论:当往集合中加入一个数xxx的时候,如果存在d∣xd|xd∣x且ddd不在集合中,那么加入ddd ...
- Codeforces Round #620 (Div. 2) F2. Animal Observation (hard version) dp + 线段树
传送门 文章目录 题意: 思路: 题意: 比如下面这个图: 思路: 对于这个题,比较容易就能考虑到dpdpdp,设f[i][j]f[i][j]f[i][j]为到了第iii行,覆盖了[j,j+k−1][ ...
最新文章
- 小米路由器4Q的设置
- Nodejs 新特性 async await 的使用 以及使用 async await 处理异步
- Python学习笔记之字典(二)
- 6 SystemVerilog语言编写售货机
- DSB2017第一名论文理解: 3D Deep Leaky Noisy-or Network(三)
- 【PYTHON笔记】:文件打开和关闭
- 烽火HG220G-U E00L2.03M2000光猫改桥接教程
- JAVASCRIPT视频教程推荐==李炎恢JavaScript教程 第一季
- Docker 视频教程 ( 猿课 )
- c#怎样将object转换过程int型
- 三插头内部结构图_两脚插头和三脚插头区别是什么 插座的结构特点有哪些
- 好用的报表工具有哪些?
- 中国睡眠经济行业发展格局与投资策略规划建议报告2022-2027年
- 恢复PyCharm顶部菜单栏
- linux卸载amd软件命令,ubuntu如何卸载软件,Ubuntu软件安装和卸载
- NOIP2016普及组复赛——T4魔法阵
- 孙宇晨真的有道歉吗?逐句解读孙宇晨避重就轻的“致歉信”
- vim中文乱码问题的解决
- 【CAD .NET】设置保存为pdf文件的页面参数 边距,横向竖向
- 《c语言程序设计》实验报告,C语言程序设计实验实验报告_wenkub
热门文章
- 金蝶osf接口开发_解决SaaS间的数据孤岛,实现SaaS数据接口集成互通互联
- oracle中sysdate函数 ro,ORACLE常用函數
- 手机鸿蒙系统体验,首位!魅族Lipro智能家居宣布接入鸿蒙系统,魅族手机还会远吗?...
- Python爬虫之(六)requests库的用法
- 跟着开源项目学因果推断——mr_uplift(十五)
- [云计算]两层网络、三层网络的理解
- 《人件(原书第3版)》—— 01 此时此刻,一个项目正在走向失败
- nginx对PHP文件报File not found.错
- 个推如何管理亿级代码的质量?持续集成SonarQube 代码质量管理系统
- Android数据库一些源码分析