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. (6)Spring Boot web开发 --- 错误处理页面

    文章目录 处理时间(`Date`)类型 thymeleaf 页面拼接字符串 映射路径占位符 使用 put.delete 方法 错误处理机制 处理时间(Date)类型 Spring Boot 进行参数绑 ...

  2. 1183: 零起点学算法90——海选女主角(C语言)

    一.题目 http://acm.wust.edu.cn/problem.php?id=1183&soj=0 二.分析 从描述来看,就是找出一个二维数组中绝对值最大的数: 带符号的32位整数,刚 ...

  3. 准备写个Golang开发的教程

    进入golang的开发已经差不多两年了,最近打算写个Golang的教程.目的是让有开发基础,没接触过Golang的人能够愉快高效地写出Golang项目. 1 记得17年底时候,有个特别小的项目,准备试 ...

  4. 创建 Python Virtualenv 虚拟隔离环境

    video:创建 Python Virtualenv 虚拟隔离环境 python 虚拟环境 venv 简单用法 - littlemore - 博客园 创建 Python Virtualenv 虚拟隔离 ...

  5. SpringCloud使用Consul作为分布式配置中心

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_36027670/article/de ...

  6. 路由基础(Routing)

    查看本机路由表: [root@controller02 ~]# cat /etc/iproute2/rt_tables # # reserved values # 255     local 254  ...

  7. iis安装ssl证书

    在证书控制台下载IIS版本证书,下载到本地的是一个压缩文件,解压后里面包含.pfx文件是证书文件,pfx_password.txt是证书文件的密码. 友情提示: 每次下载都会产生新密码,该密码仅匹配本 ...

  8. SQL链接服务器查询-OPENQUERY的使用

    OpenQuery: 用途:与其他Server交互的技术,通过它能够直接访问其他数据库资源.可以跨平台连接,包括Oracle   --创建链接服务器 exec sp_addlinkedserver ' ...

  9. django pk 和id用法

    pk就是primary key的缩写,也就是任何model中都有的主键,那么id呢,大部分时候也是model的主键,所以在这个时候我们可以认为pk和id是完全一样的. class Student(mo ...

  10. java中的权限修饰符&关键字

    1.类的权限修饰符default(不写权限修饰符),public 说明:类的权限修饰符只有default(不写权限修饰符)和public.   package world default Y N pu ...