zoukankan      html  css  js  c++  java
  • CodeForces Round #559 Div.2

    A. A pile of stones

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    string s;
    
    int main() {
        scanf("%d", &N);
        cin >> s;
        int len = s.length();
    
        int ans = 0, temp = -1;
        for(int i = len - 1; i >= 0; i --) {
            if(s[i] == '-') {
                temp = i;
                break;
            }
        }
    
        if(temp == -1) ans = len;
        else {
            int minn = 1010;
            ans = 0;
            for(int i = 0; i <= temp; i ++) {
                if(s[i] == '+') ans ++;
                else ans --;
                minn = min(minn, ans);
            }
    
            if(minn < 0) ans = -minn;
            else ans = 0;
    
            for(int i = 0; i <= temp; i ++) {
                if(s[i] == '+') ans ++;
                else ans --;
            }
            ans += len - temp - 1;
        }
    
        printf("%d
    ", ans);
    
        return 0;
    }
    View Code

    B. Expansion coefficient of the array

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 3e5 + 10;
    int N;
    int a[maxn];
    
    int main() {
        scanf("%d", &N);
        int ans = INT_MAX;
        for(int i = 1; i <= N; i ++) {
            scanf("%d", &a[i]);
            ans = min(ans, a[i] / max(i - 1, N - i));
        }
    
        printf("%d
    ", ans);
    
        return 0;
    }
    View Code

    C. The Party and Sweets

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N, M;
    long long g[maxn], b[maxn];
    
    int main() {
        scanf("%d%d", &N, &M);
        for(int i = 1; i <= N; i ++)
            scanf("%lld", &b[i]);
        for(int i = 1; i <= M; i ++) {
            scanf("%lld", &g[i]);
        }
    
    
        sort(b + 1, b + 1 + N);
        sort(g + 1, g + 1 + M);
    
        if(b[N] > g[1]) printf("-1
    ");
        else {
           long long ans = 0;
           for(int i = N; i >= 1; i --)
                ans += b[i] * M;
            for(int i = 2; i <= M; i ++)
                ans += g[i] - b[N];
    
           if(g[1] != b[N]) ans += g[1] - b[N - 1];
           printf("%lld
    ", ans);
        }
    
        return 0;
    }
    View Code

    D. The minimal unique substring

    #include <bits/stdc++.h>
    using namespace std;
    
    int N, M;
    
    int main() {
        scanf("%d%d", &N, &M);
        string s = "";
        if(M == 1) {
            s += '1';
            for(int i = 0; i < N - 1; i ++)
                s += '0';
        } else {
            int cnt = (N - M) / 2 + 1;
            for(int i = 0; i < N; i ++) {
                if(i % cnt == 0) s += '1';
                else s += '0';
            }
        }
    
        cout << s << endl;
    
        return 0;
    }
    View Code

      

  • 相关阅读:
    「SELECT~FOR UPDATE NOWAIT」
    IT精英完美的七种生活方式
    ASP.NET下载CSV文件
    对一个Frame内控件的遍历
    .Net日期与时间的取得方法
    表的字段修改(SQL语句)
    谁能给我一些软件开发相关的名言警句
    LeetCode: Add two numbers
    LeetCode: 3Sum
    LeetCode: 4Sum
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10922999.html
Copyright © 2011-2022 走看看