• Codeforces Round #616 (Div. 2)题解


    A. Even But Not Even

    链接

    https://codeforces.com/contest/1291/problem/A

    题意

    寻找特殊偶数,即本身不能被2整数但是数各位置上的数字之和能被2整除。

    现给你一个数字s,你可以进行删除某个位置上的数字的操作,但不可改变数字相对顺序,可以操作多次,求解是否能的到特殊偶数若能则输出操作后的偶数,若不能则输出-1

    解法

    注意Note的内容

    In the first test case of the example, 12271227 is already an ebne number (as 1+2+2+7=121+2+2+7=12, 1212 is divisible by 22, while in the same time, 12271227 is not divisible by 22) so we don’t need to delete any digits. Answers such as 127127 and 1717 will also be accepted.

    也就是说17就行,那么我只需要取两位奇数就行,这样一定无法被2整数,且数位之和为偶数

    代码

    int main(){
        int t; RD(t);
        while(t--){
            int n; RD(n);
            LL sum = 0;
            LL ans[3] = {0};
            int k = 0;
            string s; cin >> s;
            for(int i = 0; i < n; i++)  {
                int temp = s[i] - '0';
                if (temp%2 == 1 && k < 2){ans[k++] = temp;}
            }
            if(k < 2){ printf("-1
    ");}
            else  cout << ans[0] << ans[1] << '
    ';
        }
    }

    B. Array Sharpening

    链接

    https://codeforces.com/contest/1291/problem/B

    题意

    有一个长度为n的数组,第i位上的数字为ai,可以对每个位置上的数字进行ai = ai – 1;操作,但是要确保操作的数字目前 满足ai > 0

    解法

    举个例子

    当3个数字的时候3个位置最小值是0 1 0,5个时候5个位置最小值是0 1 2 1 0
    你判断下这个位置的数是否大于等于这个最小值

    也就是说你要确保每个位置的数大于一个数,偶数的话就是需要判断中间两位是否是否相等

    • n = 2,最小 1 1 (0, 1 | 1, 0)
    • n = 4,最小 0 2 2 0 (0,1,2,0 | 0,2,1,0)
    • ….应该很好理解
    • 就是说你n等于2的术后中间如果相等要a[i] >= n/2
    • 那么其实你只需要判断0 ~ n-1能否走完就行——>看代码

    代码

    const int maxn = 3e5 + 50;
    LL a[maxn];
    int main(){
        //freopen("in.txt", "r", stdin);
        int t; RD(t);
        while(t--){
            int n; RD(n);
            bool jud = true;
            for(int i = 0; i < n; i++){
                RD(a[i]);
            }
            int i = 0, j;
            for(i = 0; i + 1 < n && a[i + 1] >= i + 1; ++i);
            for(j = i; j < n &&a[j] >= (n - j - 1); ++j);
            if (j != n) jud = false;
            if (jud) printf("Yes
    ");
            else printf("No
    ");
        }
    }

    C

    链接

    https://codeforces.com/contest/1291/problem/C

    题意

    你和你的n-1个朋友排成一个队伍,选择ai,排在前面的优先选择,但只能选择第一个或者最后一个,每个ai只能被选择一次。

    在开始之前你可以选择k个人说服他们选择第一个还是最后一个元素,而剩余的朋友的选择是不受控制的,输出您至少获得的ai

    解法

    首先可以知道排在你身后的朋友对你的选择是没有影响的。

    代码

    const int maxn = 1e5+50;
    int a[maxn];
    int main(){
        int t; RD(t);
        while(t--){
            int n, m, k; RD(n, m, k);
            REP(i, n){RD(a[i]);}
            k = min(m-1, k);
            int ans = 0;
            for(int i = 0; i <= k; i++){
                int tmp = 1e9;
                for(int j = 0; j < m-k; j++){
                    tmp = min(tmp, max(a[i+j], a[n-1-(k-i)-(m-k-j-1)]));
    
                }
                ans = max(ans, tmp);
            }
            cout << ans << '
    ';
        }
    }

    D

    链接

    题意

    解法

    代码

    E

    链接

    题意

    解法

    代码

  • 相关阅读:
    memcache的最佳实践方案。
    ehcache memcache redis 三大缓存男高音
    微服务-----(网站架构演变)
    分布式job-任务调度(一)
    rocketmq(三 java操作rocket API, rocketmq 幂等性)
    rocketMQ(二 )Centos7 集群
    go基础三 数组,切片,map,list
    go语言基础二 函数 ,递归函数 ,指针
    go语言基础一:数据类型,变量和常量,类型转化
    Spring AOP 学习(一) 代理模式
  • 原文地址:https://www.cnblogs.com/ygbrsf/p/12582989.html
Copyright © 2020-2023  润新知