其他分享
首页 > 其他分享> > CodeForces Round #553 Div2

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\n", 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

 

标签:node,Node,const,int,namespace,CodeForces,long,553,Div2
来源: https://www.cnblogs.com/zlrrrr/p/10737771.html