Educational Codeforces Round 82 (Rated for Div. 2)

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-13 12:23:17

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\n",ans);
    }
    return 0;
}

B

好的天数是\(x = \lceil\frac{n}{2}\rceil\),那么优先考虑x
x天需要\(\lceil\frac{x}{g}\rceil\)个g天去完成,但是最后一个g天不一定用完,比如n = 10,g = 2,需要 2,2,1去完成
那么\((\lceil\frac{x}{g}\rceil - 1) * (g + b) + x - (\lceil\frac{x}{g}\rceil - 1) * g = x + (\lceil\frac{x}{g}\rceil - 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,'\0');
        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] == '\0' && !seen[c - 'a'])
                --index,kb[index] = c;
            else if(kb[index + 1] == '\0' && !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\n";
        }else{
            cout << "YES\n";
            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('\n');
        }
    }
    return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!