AtCoder Beginner Contest 158 BCD

AtCoder Beginner Contest 158 BCD

B

先找到循环节的长度乘以每个循环节中\(a\) 的数量,然后在加上

注意 long long

#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n,a,b;
    cin >> n >> a >> b;
    cout <<( n / (a + b) * a + min(a,n % (a + b)) );
    return 0;
}

C

枚举

\(O(1)\) 解法 先算出max(ceil(a/0.08),ceil(b/0.1)),再看这个数能否回去

#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    for(int i = 1;i <= 1250; ++i) {
        if(floor(i * 0.08) == a && floor(i * 0.1) == b) {
            cout << i ;
            return 0;
        }
    }
    cout << -1;
    return 0;
}

D

加个反转标记,deque的插入删除都是\(O(1)\)

https://blog.csdn.net/like_that/article/details/98446479

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    deque<char> q;
    string s;
    int Q,t,f;
    bool k = 1;
    char c;
    cin >> s >> Q;
    for(int i = 0;i < s.size(); ++i) {
        q.push_back(s[i]);
    }
    while(Q --) {
        cin >> t;
        if(t == 1) k = !k;
        else {
            cin >> f >> c;
            if(f == 1) {
                if(k == 1) q.push_front(c);
                else q.push_back(c);
            }
            else {
                if(k == 1) q.push_back(c);
                else q.push_front(c);
            }
        }
    }
    if(k) for(int i = 0;i < q.size(); ++i) cout << q[i] ;
    else for(int i = q.size() - 1;i >= 0; --i) cout << q[i];
    return 0;
}
posted @ 2020-03-13 23:44  南风--  阅读(119)  评论(0编辑  收藏  举报