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. 01 IO流(一)—— 流的概念、File类

    1 流的概念理解(重要) 理解流的概念非常重要. 流,就是程序到数据源或目的地的一个通道. 我们把这个通道实例化得到一个具体的流,相当于一个数据传输工具,它可以在程序与资源之间进行数据交换. 换言之, ...

  2. spring 条件化配置

    步骤一: 实现接口:org.springframework.context.annotation.Condition import org.springframework.context.annota ...

  3. 题解-CSA Beta Round#1 Number Elimination

    Problem CSA-Beta Round#3 题意概要:给定 \(n\) 个数组成的序列,定义一次操作: 在当前序列中选择两个数,将其中较小的数从序列中删除(若两个数相同,则删除在序列中更靠前的) ...

  4. U盘安装Ubuntu14.04&配置远程win10远程连接

    1.U盘安装Ubuntu:https://blog.csdn.net/baigoocn/article/details/26561473 2.win10远程访问Ubuntu系统:https://www ...

  5. VBA用户自定义函数(十五)

    函数是一组可重复使用的代码,可以在程序中的任何地方调用.这消除了一遍又一遍地编写相同的代码的需要.这使程序员能够将一个大程序划分成许多小的可管理的功能模块. 除了内置函数外,VBA还允许编写用户定义的 ...

  6. 将网址url中的参数转化为JSON格式的两种方法

    在我们进入主题前,我先先看下获取网址URL的方法: window.location.href // 设置或获取整个URL为字符串 window.location.hash // 设置或获取href属性 ...

  7. Bootstrap源码

    1.Bootstrap Bootstrap是美国Twitter公司的设计师Mark Otto和Jacob Thornton合作基于HTML.CSS.JavaScript 开发的简洁.直观.强悍的前端开 ...

  8. stm32 CAN通信 TJA1040

    CAN协议特点 1.多主控制 所有单元都可以发送消息,根据标识符(Identifier简称ID)决定优先级.仲裁获胜(被判定为优先级最高)的单元可继续发送消息,仲裁失利的单元则立刻停止发送而进行接收工 ...

  9. volatile和锁

    让编译器不要将变量缓存到寄存器,而是每次去访问主板上的内存 可见性 对一个volatile变量的读,总是能看到(任意线程)对这个volatile变量最后的写入 原子性 对任意单个volatile变量的 ...

  10. IDEA提示不区分大小写设置

    File–>Settings–>Editor–>General–>Code Completion–>Mach case的勾取消掉就可以了 取消勾后效果如下