Codeforces Round #555 div3 C2

题目大意

给出一个序列,可以从左或从右侧取数,要求取出的序列严格上升

思路

贪心取左右最小的,如果相等则之后只能从一侧取,直接选能取最长的一侧

Code:

 #include<bits/stdc++.h> 

#define ll long long 

#define inf 0x3f3f3f3f
using namespace std; 

int ma[10];
int n;
int a[(int)(2*1e5)+10];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
    }
    int cmin = 0;
    int l = 1,r=n;
    vector<int> ans;
    while(l<=r && cmin<max(a[l],a[r])){
        if(a[l]==a[r]){
            if(r-l<3){
                ans.push_back(0);
                cmin = a[l++];
            }
            else{
                int cntl=0,cntr=0;
                int ind = l+1;
                while(a[ind]>a[ind-1]) cntl++,ind++;    //左边可取的长度
                ind = r-1;
                while(a[ind]>a[ind+1]) cntr++,ind--;    //右边可取的长度
                if(cntl>cntr){
                    ans.push_back(0);
                    cmin = a[l++];
                }else{
                    ans.push_back(1);
                    cmin = a[r--];
                }
            }
            continue;
        }
        // cmin<a[l]<a[r] 或 a[r] < cmin < a[l]
        if((a[l]<a[r] && cmin<a[l] )|| cmin>=a[r]){
            ans.push_back(0);
            cmin = a[l++];
        }else{  // cmin < a[r] < a[l] 或 a[l] < cmin < a[r]
            ans.push_back(1);
            cmin = a[r--];
        }
    }
    printf("%d\n",ans.size());
    for(int i:ans){
        if(i==0)printf("L");
        else printf("R");
    }
    printf("\n");
    return 0;
}
}

原文地址:https://www.cnblogs.com/xxrlz/p/10777436.html

时间: 2024-08-15 23:37:37

Codeforces Round #555 div3 C2的相关文章

【赛时总结】◇赛时&#183;V◇ Codeforces Round #486 Div3

◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了--为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Substrings Sort +传送门+   [暴力模拟] 题意 给出n个字符串,你需要将它们排序,使得对于每一个字符串,它前面的字符串都是它的子串(对于字符串i,则字符串 1~i-1 都是它的子串). 解析 由于n最大才100,所以 O(n3) 的算法都不会爆,很容易想到暴力模拟. 如果字符串i是字符串j的子串

Codeforces Round #605(Div3)A~E

Codeforces Round #605(Div3)A~E A. Three Friends 题意: 给三个数\(a,b,c\),对每一个数字可以进行一次操作,加一减一或者不变. 求三个数两两组合的差值绝对值的最小值. 思路: 先排个序. 假设排序后三个数从小到大是\(a,b,c\). 那么他们的两两差就是\((c-b)+(c-a)+(b-a)=2c-2a\). 为了让他们的\(2c-2a\)最小,那就缩小\(c\),增大\(a\). #include<bits/stdc++.h> usin

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>

Codeforces Round #555 (Div. 3)[1157]题解

不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreagonm上蓝果然没有食言qwq). (震惊...HA省A队CF青名...) CF1157A Reachable Numbers 水题,分析一下不难发现不超过\(10\)次就会少一位,然后\(10^9\)范围内的数可以到达的数个数显然不多,不妨大力模拟,然后把出现的数扔进set,最后输出set.size(

CodeForces Round #527 (Div3) C. Prefixes and Suffixes

http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some string ss of length nn consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and s

Codeforces Round #555 Div. 3

题目链接:戳我 完了,最菜就是我了.div.3都写不动QAQ A 按照题意模拟即可,注意判重 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<map> #define MAXN 100010 using namespace std; int

CodeForces Round #498 div3

A: 题目没读, 啥也不会的室友帮我写的. 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout); 4 #define LL long long 5 #define ULL unsigned LL 6 #define f

D. Circular Dance codeforces round#529(div3)

这道题类似与经典题目素数和环,每次找到后两个数字a,b,如果a没被访问过且a是b的父节点(a记得b),就继续把a当下一个节点搜,否则把b当下一个节点搜 值得注意的是当搜到只剩下一个节点的时候,要选取那个没有访问过的节点做最后一个节点,因此需要标记数组 #include<bits/stdc++.h> using namespace std; int a[200010],b[200010]; bool vis[200010]; int n; void dfs(int step,int num) {

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

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