Codeforces Round #555 (Div. 3) C1,C2【补题】
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【补题】的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution
对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #350 (Div. 2) C. Cinema 水题
C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...
- Codeforces Round #555 (Div. 3) c2 d e f
c2:Increasing Subsequence (hard version) 那边小取那边,然后相等比较后面的长度 #include<bits/stdc++.h> using name ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
- Codeforces Round #555 (Div. 3) A B C1(很水的题目)
A. Reachable Numbers 题意:设f(x)为 x+1 这个数去掉后缀0的数,现在给出n,问经过无数次这种变换后,最多能得到多少个不同的数. 代码 #include<cstdio& ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version) (贪心)
题意:给你一组数,每次可以选队首或队尾的数放入栈中,栈中元素必须保持严格单增,问栈中最多能有多少元素,并输出选择情况. 题解:首先考虑队首和队尾元素不相等的情况,如果两个数都大于栈顶元素,那么我们选小 ...
- CodeForces Round #555 Div.3
A. Reachable Numbers 代码: #include <bits/stdc++.h> using namespace std; ; int N; set<int> ...
随机推荐
- 人工智能对人类有哪些影响 选择Python入门怎样
人工智能对人类有哪些影响?选择Python入门怎样?人工智能是科技时代进步的产物,也是目前人们非常关注的一个产业.那么,随着人工智能的发展,对人类生活的有哪些影响呢? 1.人工智能对文化产业影响 据了 ...
- Apache Shiro初认识
Apache Shiro 一.Shiro介绍: Apache软件基金会专门针对系统中的登录.加密.权限认证.授权等等功能进行了封装,不仅仅适用于JavaWeb项目,CS架构的系统也可以使用Shiro. ...
- oracle给用户授权存储过程
https://www.jianshu.com/p/fab356d68ae2 grant connect,resource to xinomonitor; 发现不能进行断点调试,然后授如下权限 gra ...
- Challenge & Growth —— 从这里开始
做有挑战的事情,就从这里开始. 忘记这本书现在在哪儿了,以前还以为能祖祖辈辈留传,现在只能借助 Nowcoder 了.Now coder,Forever thinker. 想以自以为最优美的 code ...
- SVN_03绿色版
1.首先备份当前安装visualSVN文件的bin目录,万一出错还能反个水.一般默认安装路径是C:\Program Files(x86)VisualSVN\bin 2.然后运行ildasm,Windo ...
- C# async 和 await 理解
C# async 和 await 理解 先假设如下场景: 主函数 Main,循环等待用户输入: 计算函数 Cal,耗时计算大量数据: class Test { static int Main(stri ...
- Action请求后台出现Response already commited异常解决方法
在编写导出功能使用action请求,在处理导出异常时期望跳转异常页,Controller中的方法返回类型String的url 在处理完逻辑导出文件后后台控制台出现 WARN [org.springf ...
- Qt定时器
PS: 本案例使用的是Qt 4.8.4版本,不同版本代码可能会有差异. 第一步: // 重写此虚函数(继承自QObject) virtual void timerEvent(QTimerEvent* ...
- HANA数据库无法停止
Symptom: 使用命令HDB stop多次,每次报错为timeout ----------------------- sdpadm@PRDDB01:/usr/sap/SDP/HDB66/prder ...
- ArduPilot简介
源码地址:https://github.com/ArduPilot/ardupilot/ 参考:http://ardupilot.org/dev/docs/learning-the-ardupilot ...