zoukankan      html  css  js  c++  java
  • Codeforces Round #677 (Div. 3)【ABCDE】

    比赛链接:https://codeforces.com/contest/1433

    A. Boring Apartments

    题解

    模拟即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t;
        cin >> t;
        while (t--) {
            int n;
            cin >> n;
            int ans = 0;
            for (int i = 1; i <= 9; i++) {
                int num = 0;
                for (int j = 0; j < 4; j++) {
                    num = num * 10 + i;
                    ans += to_string(num).size();
                    if (num == n) break;
                }
                if (num == n) break;
            }
            cout << ans << "
    ";
        }
        return 0;
    }
    

    B. Yet Another Bookshelf

    题解

    每次可以选取最左或最右端的书本合并,所以答案即两两书本间的空隙个数。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t;
        cin >> t;
        while (t--) {
            int n;
            cin >> n;
            vector<int> pos;
            for (int i = 0; i < n; i++) {
                int x;
                cin >> x;
                if (x == 1) pos.push_back(i);
            }
            int ans = 0;
            for (int i = 1; i < int(pos.size()); i++) 
                ans += pos[i] - pos[i - 1] - 1;
            cout << ans << "
    ";
        }
        return 0;
    }
    

    C. Dominant Piranha

    题解

    如果全为一个值,那么一定无解。否则,一定有一个最大值左右有一个值小于它,找到这个最大值即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t;
        cin >> t;
        while (t--) {
            int n;
            cin >> n;
            vector<int> a(n);
            int mx = 0;
            for (auto &x : a) cin >> x, mx = max(mx, x);
            if (all_of(a.begin(), a.end(), [&](int x) { return x == mx; })) {
                cout << -1 << "
    ";
            } else {
                int ans = -1;
                for (int i = 0; i < n; i++) {
                    if (a[i] == mx) {
                        if (i - 1 >= 0 and a[i - 1] < a[i]) {
                            ans = i;
                            break;
                        }
                        if (i + 1 < n and a[i + 1] < a[i]) {
                            ans = i;
                            break;
                        }
                    }
                }
                cout << ans + 1 << "
    ";
            }
        }
        return 0;
    }
    

    D. Districts Connection

    题解

    如果所有地区都属于一个组织,那么一定无解。
    否则将第一个组织第一个地区和其他组织所有地区相连,将第一个组织其他地区和其他组织任意地区相连即可。

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int t;
        cin >> t;
        while (t--) {
            int n;
            cin >> n;
            vector<int> a(n);
            for (auto &x : a) cin >> x;
            if (all_of(a.begin(), a.end(), [&](int x) { return x == a[0]; })) {
                cout << "NO" << "
    ";
            } else {
                cout << "YES" << "
    ";
                map<int, vector<int>> mp;
                for (int i = 0; i < n; i++) {
                    mp[a[i]].push_back(i);
                }
                vector<vector<int>> v;
                for (auto [x, vec] : mp) {
                    v.emplace_back(vec);
                }
                for (int i = 1; i < int(v.size()); i++) {
                    for (auto j : v[i]) {
                        cout << v[0].front() + 1 << ' ' << j + 1 << "
    ";
                    }
                }
                for (int i = 1; i < int(v[0].size()); i++) {
                    cout << v[1].front() + 1 << ' ' << v[0][i] + 1 << "
    ";
                }
            }
        }
        return 0;
    }
    

    E. Two Round Dances

    题解

    (n) 个人均分为两组:(frac{C_n^{frac{n}{2}}}{2})
    (frac{n}{2}) 个人围成一圈:((frac{n}{2}-1)!)
    答案即:(frac{C_n^{frac{n}{2}}}{2} imes ({frac{n}{2}}-1)! ^2) ,化简得 (frac{2(n-1)!}{n})

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        cin >> n;
        long long fac = 1;
        for (int i = 1; i <= n - 1; i++) fac *= i;
        cout << 2 * fac / n << "
    ";
        return 0;
    }
    
  • 相关阅读:
    uni-app 发起请求,Toast 消息提示 ,跳转页面
    uView初识
    uni-app初识
    docker目录 /var/lib/docker/containers 日志清理
    Linux中使用pigz工具更快的压缩和解压文件
    docker 修改默认网段
    LayaAir提示:版本不匹配!全局tsc(2.7.2)!=VS Code的语言服务(2.1.5)。可能出现不一致的编译错误
    C++ 格式化 浮点为字符串
    安装 ta-lib
    编译 python 代码
  • 原文地址:https://www.cnblogs.com/Kanoon/p/13850003.html
Copyright © 2011-2022 走看看