码迷,mamicode.com
首页 > 其他好文 > 详细

Educational Codeforces Round 82 (Rated for Div. 2)

时间:2020-02-13 12:35:27      阅读:41      评论:0      收藏:0      [点我收藏+]

标签:ble   har   stream   def   char s   tor   double   std   names   

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;
}

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

Educational Codeforces Round 82 (Rated for Div. 2)

标签:ble   har   stream   def   char s   tor   double   std   names   

原文地址:https://www.cnblogs.com/Emcikem/p/12303041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!