Educational Codeforces Round 82 (Rated for Div. 2)

Posted emcikem

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 82 (Rated for Div. 2)相关的知识,希望对你有一定的参考价值。

A

1必须和1相邻,把所有1和1之间的0去掉即可,就是统计1和1之间有多少个0

#include <iostream>
#include <cstdio>
#include <vector>
int main(){
    int T;
    read(T);
    while(T--){
        char s[105];
        cin >> s;
        int len = strlen(s);
        std::vector<int> v;
        for(int i = 0; i < len; i++){
            if(s[i] == '1')v.push_back(i);
        }
        int ans = 0;
        for(int i = 1; i < v.size(); i++){
            ans += v[i] - v[i - 1] - 1;
        }
        printf("%d
",ans);
    }
    return 0;
}

B

好的天数是(x = lceilfrac{n}{2} ceil),那么优先考虑x
x天需要(lceilfrac{x}{g} ceil)个g天去完成,但是最后一个g天不一定用完,比如n = 10,g = 2,需要 2,2,1去完成
那么((lceilfrac{x}{g} ceil - 1) * (g + b) + x - (lceilfrac{x}{g} ceil - 1) * g = x + (lceilfrac{x}{g} ceil - 1) * b)就是完成质量好的项目的最小个数
然后这个答案与n进行比较,输出大的即可

#include <iostream>
#include <cmath>
int main(){
    int T;
    read(T);
    while(T--){
        ll n,g,b;
        cin >> n >> g >> b;
        ll x = ceil((double)n/2);
        ll t = ceil(double(x)/g);
        cout << max(n,x + (t - 1) * b) << endl;
    }
    return 0;
}

C

模拟一下,类似一个双端队列,先把给出的字符串的第一个字符加入队列,然后遍历字符串

#include <iostream>
#include <vector>
#include <array>
#include <cstring>
#include <string>
using namespace std;
int main(){
    int t;cin >> t;
    while(t--){
        string s;cin >> s;
        std::vector<char > kb(100,'');
        kb[50] = s[0];
        int index = 50;
        int l = 50,r = 50;
        bool pos = true;
        array<bool,26>seen = {0};
        seen[s[0] - 'a'] = true;
        for(int j = 1; j < s.length(); j++){
            char c = s[j];
            if(kb[index - 1] == c)
                index--;
            else if(kb[index + 1] == c)
                index++;
            else if(kb[index - 1] == '' && !seen[c - 'a'])
                --index,kb[index] = c;
            else if(kb[index + 1] == '' && !seen[c - 'a'])
                ++index,kb[index] = c;
            else{
                pos = false;
                break;
            }
            seen[c - 'a'] = true;
            l = min(l,index);r = max(r,index);
        }
        if(!pos){
            cout << "NO
";
        }else{
            cout << "YES
";
            for(int i = l; i <= r; i++)putchar(kb[i]);
            for(int i = 0; i < 26; i++){
                if(!seen[i])putchar((char)('a' + i));
            }
            putchar('
');
        }
    }
    return 0;
}

然后,我太菜了,只做了3题

以上是关于Educational Codeforces Round 82 (Rated for Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27