Codeforces Round #568 Div.2

A. Ropewalkers

#include <bits/stdc++.h>
using namespace std;
 
int num[5];
int d;
 
int main() {
    for(int i = 0; i < 3; i ++)
        scanf("%d", &num[i]);
    scanf("%d", &d);
    
    sort(num, num + 3);
    int ans = 0;
    
    if(num[1] - num[0] < d)
        ans += d - num[1] + num[0];
    if(num[2] - num[1] < d)
        ans += d - num[2] + num[1];
    
    printf("%d\n", ans);
    
    return 0;
}
View Code

B. Email from Polycarp

#include <bits/stdc++.h>
using namespace std;
int T;
string s, t;

bool isSubsequence(string s, string t) {
    int ls = s.length(), lt = t.length();
    if(!ls) return true;
    if(!lt && ls) return false;
     
    int pos = 0, temp = 0;
    char c = s[pos];
    while(pos <= ls && temp <= lt) {
        if(s[pos] == t[temp]) {
            c = s[pos];
            pos ++;
        } else {
            if(t[temp] != c) return false;
        }
        temp ++;
    }
    return pos == ls + 1;
}

int main() {
    scanf("%d", &T);
    while(T --) {
        cin >> s >> t;
        if(isSubsequence(s, t)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
View Code

C1. Exam in BerSU (easy version)

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N, M;
int a[maxn];
long long num[110];

int main() {
    scanf("%d%d", &N, &M);
    memset(num, 0, sizeof(num));
    for(int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
        long long ans = 0, maxx = 0;
        long long sum = M - a[i];
        for(int j = 1; j <= 100; j ++) {
            long long temp = min(sum / j, num[j]);
            maxx += temp;
            sum -= temp * j;
        }
        num[a[i]] ++;
        printf("%lld%s", i - maxx, i != N - 1 ? " " : "\n");
    }
    
    return 0;
}
View Code

C2. Exam in BerSU (hard version)

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int N, M;
int a[maxn];
long long num[110];

int main() {
    scanf("%d%d", &N, &M);
    memset(num, 0, sizeof(num));
    for(int i = 0; i < N; i ++) {
        scanf("%d", &a[i]);
        long long ans = 0, maxx = 0;
        long long sum = M - a[i];
        for(int j = 1; j <= 100; j ++) {
            long long temp = min(sum / j, num[j]);
            maxx += temp;
            sum -= temp * j;
        }
        num[a[i]] ++;
        printf("%lld%s", i - maxx, i != N - 1 ? " " : "\n");
    }
    
    return 0;
}
View Code

 

被病毒吓到不敢出门 QAQ 废宅好几天重于开始干活辽 接下来打算看书去辽 为开工上班做准备!

posted @ 2020-01-28 15:06  丧心病狂工科女  阅读(171)  评论(0编辑  收藏  举报