• AtCoder Beginner Contest 177


    比赛链接:https://atcoder.jp/contests/abc177/tasks

    A - Don't be late

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int d, t, s; 
        cin >> d >> t >> s;
        cout << (t * s >= d ? "Yes" : "No") << "
    ";
    }

    B - Substring

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        string s, t;
        cin >> s >> t;
        int ans = INT_MAX;
        for (int i = 0; i + t.size() <= s.size(); i++) {
            int change = 0;
            for (int j = 0; j < t.size(); j++)
                if (s[i + j] != t[j]) 
                    ++change;
            ans = min(ans, change);
        }
        cout << ans << "
    ";
    }

    C - Sum of product of pairs

    #include <bits/stdc++.h>
    using namespace std;
    constexpr int mod = 1e9 + 7;
    int main() {
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        vector<long long> pref(n);
        for (int i = 0; i < n; i++) {
            if (i == 0) pref[i] = a[i];
            else pref[i] = pref[i - 1] + a[i];
        }
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[i] * ((pref[n - 1] - pref[i]) % mod) % mod;
            ans %= mod;
        }
        cout << ans << "
    ";
    }

    D - Friends

    原题hdu 1856

    #include <bits/stdc++.h>
    using namespace std;
    constexpr int N = 2e5 + 100;
    
    int fa[N], son_num[N];
    
    int Find(int x) {
        if (fa[x] == x) return fa[x];
        else return fa[x] = Find(fa[x]);
    }
    
    void Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x != y) {
            fa[y] = x;
            son_num[x] += son_num[y];
        }
    }
    
    void Init() {
        for (int i = 0; i < N; i++) {
            fa[i] = i;
            son_num[i] = 1;
        }
    }
    
    int main() {
        Init();
        int n, m;
        cin >> n >> m;
        for (int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            Union(x, y);
        }
        cout << *max_element(son_num, son_num + N) << "
    ";
    }

    E - Coprime

    #include <bits/stdc++.h>
    using namespace std;
    constexpr int N = 1e6 + 100;
    
    int p[N];
    
    void init() {
        for (int i = 2; i < N; i++) {
            if (p[i]) continue;
            for (int j = i; j < N; j += i) {
                p[j] = i;
            }
        }
    }
    
    int main() {
        init();
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        vector<set<int>> div(n);
        for (int i = 0; i < n; i++) {
            for (int j = a[i]; p[j] != 0; j /= p[j]) {
                div[i].insert(p[j]);
            }
        }
        bool pairwise = true;
        map<int, int> cnt;
        for (int i = 0; i < n; i++) {
            for (const auto &x : div[i]) {
                if (++cnt[x] >= 2)
                    pairwise = false;
            }
        }
        bool setwise = false;
        int gcd = 0;
        for (int i = 0; i < n; i++)
            gcd = __gcd(gcd, a[i]);
        if (gcd == 1) 
            setwise = true;
        if (pairwise)
            cout << "pairwise coprime" << "
    ";
        else if (setwise)
            cout << "setwise coprime" << "
    ";
        else
            cout << "not coprime" << "
    ";
    }
  • 相关阅读:
    JS判断浏览器
    【JS】时间不足10位补0方案
    【js学习小计】
    【Tangram】 通过监听进行事件触发
    JavaScript CSS Style属性对照表
    Resolve and Remove "BAD PASSWORD: It is Based on a Dictionary Word "in Linux
    [C++]关键字explicit
    [转]CentOS设置程序开机自启动的方法
    SqlServerCLR聚合函数:分组连接字符串
    vmware centos 虚拟机复制
  • 原文地址:https://www.cnblogs.com/Kanoon/p/13583540.html
Copyright © 2020-2023  润新知