• CodeForces Round #553 Div2


    A. Maxim and Biology

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    string s;
    int minn = 0x3f3f3f3f;
    
    int main() {
        scanf("%d", &N);
        cin >> s;
        for(int i = 0; i <= N - 4; i ++) {
            int cnt = 0;
            for(int j = i; j < i + 4; j ++) {
                if(j == i) {
                    if(s[j] == 'Z') cnt += 1;
                    else cnt += min(s[j] - 'A', ('Z' - s[j] + 1));
                }
                if(j == i + 1) cnt += min(abs(s[j] - 'C'), ('Z' - s[j] + 3));
                if(j == i + 2) cnt += min(abs(s[j] - 'T'), (s[j] - 'A' + 7));
                if(j == i + 3) cnt += min(abs(s[j] - 'G'), ('Z' - s[j] + 7));
            }
            minn = min(minn, cnt);
        }
        printf("%d
    ", minn);
        return 0;
    }
    
    /*
    9
    AAABBBCCC
    */
    View Code

    C. Problem for Nazar

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int mod = 1e9 + 7;
    long long l, r;
    
    long long sum(long long x) {
        if(x <= 0) return 0;
        int flag = 1;
        long long t = 1;
        long long sum1 = 0, sum2 = 0;
        for(long long i = 0; i < x; ) {
            long long nx = min(i + t, x);
            if(flag) sum1 += (nx - i);
            else sum2 += (nx - i);
    
            t *= 2;
            i = nx;
            flag ^= 1;
        }
        long long ans = sum2 % mod * ((sum2 + 1) % mod) % mod + sum1 % mod * (sum1 % mod) % mod;
        return ans % mod;
    }
    
    int main() {
        cin >> l >> r;
        cout << (sum(r) - sum(l - 1) + mod) % mod << endl;
    
        return 0;
    }
    View Code

    D. Stas and the Queue at the Buffet

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N;
    
    struct Node {
        long long a;
        long long b;
    }node[maxn];
    
    bool cmp(const Node &n, const Node &m) {
        return (n.a - n.b) > (m.a - m.b);
    }
    
    int main() {
        scanf("%d", &N);
        for(int i = 1; i <= N; i ++)
            cin >> node[i].a >> node[i].b;
    
        sort(node + 1, node + 1 + N, cmp);
        long long ans = 0;
        for(int i = 1; i <= N; i ++)
            ans += (node[i].a * (i - 1) + node[i].b * (N - i));
    
        cout << ans << endl;
    
        return 0;
    }
    View Code

     E. Number of Components

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N;
    long long a[maxn];
    
    
    int main() {
        scanf("%d", &N);
        for(int i = 1; i <= N; i ++)
            cin >> a[i];
    
        long long ans = 0;
        for(int i = 1; i <= N; i ++) {
            if(a[i] > a[i - 1])
                ans += (a[i] - a[i - 1]) * (N - a[i] + 1);
            else if(a[i] != a[i - 1])
                ans += (a[i - 1] - a[i]) * a[i];
        }
    
        cout << ans << endl;
    
        return 0;
    }
    View Code
  • 相关阅读:
    Java 报错 -source 1.5 中不支持 diamond 运算符
    MacBook Java开发环境的配置
    MacBook 版本控制工具
    版本控制工具 Git SourceTree SSH 连接码云
    接口 请求https接口
    快递 共享电子面单
    快递 已发货订单重新打印电子面单
    SQL Server 分部分项导入后 数据的修改
    Hive数据的存储以及在centos7下进行Mysql的安装
    Hive初体验
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10737771.html
Copyright © 2020-2023  润新知