D1:思路:L,R指针移动,每次选最小的即可。

 #include<bits/stdc++.h>

 using namespace std;
#define int long long
#define N 200009
int arr[N];
int ans[N];
signed main(){
int n;
cin>>n;
for(int i=;i<=n;i++){
cin>>arr[i];
}
int l=,r=n;
int cnt=;
int now=;
while(){
if(now<arr[l]&&now<arr[r]){
if(arr[l]<arr[r]){ ans[++cnt]=;
now=arr[l];
l++;
}else{ ans[++cnt]=;
now=arr[r];
r--;
}
}else if(now<arr[l]){ ans[++cnt]=;
now=arr[l];l++;
}else if(now<arr[r]){ ans[++cnt]=;
now=arr[r];r--;
}else{
break;
}
}
cout<<cnt<<'\n';
for(int i=;i<=cnt;i++){
if(ans[i])
cout<<"R";
else
cout<<"L"; }
return ;
}

D1:思路:L,R指针移动,每次选最小的即可。【注意:特判左右两个数相等即可】

 #include<bits/stdc++.h>

 using namespace std;
#define int long long
#define N 200009
int arr[N];
int ans[N];
signed main(){
int n;
cin>>n;
for(int i=;i<=n;i++) cin>>arr[i];
int l=,r=n;
int cnt=;
int now=;
while(){
if(arr[l]==arr[r]&&l<r&&arr[l]>now){
//cout<<"==";
int temp;
temp=l;
int sum1=;
while(arr[temp]<arr[temp+]&&(temp+)<r){
temp++;
sum1++;
}
temp=r;
int sum2=;
while(arr[temp]<arr[temp-]&&(temp-)>l){
temp--;
sum2++;
}
if(sum1>sum2){
ans[++cnt]=;
now=arr[l];
l++;
}else{
ans[++cnt]=;
now=arr[r];
r--;
}
}else if(now<arr[l]&&now<arr[r]){
if(arr[l]<arr[r]){
ans[++cnt]=;
now=arr[l];
l++;
}else{
ans[++cnt]=;
now=arr[r];
r--;
}
}else if(now<arr[l]){ ans[++cnt]=;
now=arr[l];l++;
}else if(now<arr[r]){ ans[++cnt]=;
now=arr[r];r--;
}else{
break;
}
}
cout<<cnt<<'\n';
for(int i=;i<=cnt;i++){
if(ans[i])
cout<<"R";
else
cout<<"L";
}
return ;
} /*
1 3 5 4 2 1
15
37504 79054 80071 95721 135743 164345 189260 190810 191657 196168 200000 200000 190810 190018 185437
*/

左右两端数都小于等于构造的数组的最后一个数字

Codeforces Round #555 (Div. 3) C1,C2【补题】的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution

    对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...

  3. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  4. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

  5. Codeforces Round #555 (Div. 3) c2 d e f

    c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...

  6. Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】

    一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...

  7. Codeforces Round #555 (Div. 3) A B C1(很水的题目)

    A. Reachable Numbers 题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数. 代码 #include<cstdio& ...

  8. Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version) (贪心)

    题意:给你一组数,每次可以选队首或队尾的数放入栈中,栈中元素必须保持严格单增,问栈中最多能有多少元素,并输出选择情况. 题解:首先考虑队首和队尾元素不相等的情况,如果两个数都大于栈顶元素,那么我们选小 ...

  9. CodeForces Round #555 Div.3

    A. Reachable Numbers 代码: #include <bits/stdc++.h> using namespace std; ; int N; set<int> ...

随机推荐

  1. kafka 集群环境搭建 java

    简单记录下kafka集群环境搭建过程, 用来做备忘录 安装 第一步: 点击官网下载地址 http://kafka.apache.org/downloads.html 下载最新安装包 第二步: 解压 t ...

  2. hashCode和identifyHashCode的区别

    API: System类提供一个identifyHashCode(Object o)的方法,该方法返回指定对象的精确hashCode值,也是根据该对象的地址计算得到的HashCode值.当某个类的ha ...

  3. QueryList::Query() The received content is empty!的经准灵活解决办法

    QueryList::Query() The received content is empty! 最近因为项目问题出现The received content is empty!,我也有过在网上寻找 ...

  4. Composer简介

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 依赖管理 Composer 不是一个包管理器.是的,它涉及 "package ...

  5. LINUX CGROUP总结

    简介: Linux CGroup全称Linux Control Group, 是Linux内核的一个功能,用来限制,控制与分离一个进程组群的资源(如CPU.内存.磁盘输入输出等).这个项目最早是由Go ...

  6. sql 语句实现一串数字位数不足在左侧补0的技巧

    https://www.cnblogs.com/mylydg/p/5725189.html 在日常使用sql做查询插入操作时,我们通常会用到用sql查询一串编号,这串编号由数字组成.为了统一美观,我们 ...

  7. 委托、Action泛型委托、Func泛型委托、Predicate泛型委托的用法

    一.举一委托场景:天气很热,二狗子想去买瓶冰镇可乐,但是二狗子很懒,于是他想找个人代他去,于是要有个代理人. 创建代理人之前先定义委托:public delegate string BuyColaDe ...

  8. [转载]Python 包管理工具

    [转载]Python 包管理工具 最近由于机缘巧合,使用各种方法安装了一些Python包,所以对Python的包管理开始感兴趣.在网上找到一篇很好的文章:https://blog.zengrong.n ...

  9. python之简单爬取一个网站信息

    requests库是一个简介且简单的处理HTTP请求的第三方库 get()是获取网页最常用的方式,其基本使用方式如下 使用requests库获取HTML页面并将其转换成字符串后,需要进一步解析HTML ...

  10. [转发]C++中new和malloc的区别

    原文地址:https://blog.csdn.net/linux_ever/article/details/50533149 new与malloc的10点区别 1. 申请的内存所在位置 new操作符从 ...