• Codeforces Round #697 (Div. 3)


    Codeforces Round #697 (Div. 3)

    A - Odd Divisor

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            ll n; cin >> n;
            while (n % 2 == 0) n /= 2;
            cout << (n > 1 && (n & 1) ? "YES
    " : "NO
    ");
        }
        return 0;
    }
    

    B - New Year's Number

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n;
            int c = n / 2020; n %= 2020;
            cout << (n <= c ? "YES
    " : "NO
    "); 
        }
        return 0;
    }
    

    C - Ball in Berland

    计数, 去重

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m >> k; vector<PII> a(k); VI x(n + 1), y(m + 1);
            rep (i, 0, k - 1) cin >> a[i].fi;
            rep (i, 0, k - 1) cin >> a[i].se;
            sort(all(a)); a.erase(unique(all(a)), a.end());
            for (auto &i : a) ++x[i.fi], ++y[i.se];
            ll ans = 0;
            rep (i, 0, a.size() - 1) {
                --x[a[i].fi], --y[a[i].se];
                ans += a.size() - i - 1 - x[a[i].fi] - y[a[i].se];
            }
            cout << ans << '
    ';
        }
        return 0;
    }
    

    D - Cleaning the Phone

    按内存从大到小排序, 然后选择0~k-1 应用卸载, 并将0~k-1中的价值为2的选出来, 把剩下的价值为1的选出来

    不断选择剩下最大内存的1去替换选中的2, 不断取价值最小值就行

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n >> m; vector<PLL> a(n); multiset<PLL> st, y;
            rep(i, 0, n - 1) cin >> a[i].fi;
            rep(i, 0, n - 1) cin >> a[i].se;
            sort(all(a), greater<PLL>());
            ll k = 0, cur = 0, g = 0, mi;
            while (k < n && cur < m) {
                cur += a[k].fi, g += a[k].se;
                if (a[k].se == 2) st.insert(a[k]);
                ++k;
            }
            if (cur < m) { cout << "-1
    "; continue; } mi = g;
            for (int i = k; i < n && cur; ++i) if (a[i].se == 1) y.insert(a[i]);
            while (!st.empty()) {
                auto it = st.begin();
                cur -= it->fi, g -= it->se; st.erase(it);
                while (!y.empty() && cur < m) {
                    auto mx = *y.rbegin();
                    cur += mx.fi, g += mx.se;
                    y.erase(y.find(mx));
                }
                if (cur < m) break;
                umin(mi, g);
            }
            cout << mi << '
    ';
        }
        return 0;
    }
    

    E - Advertising Agency

    求个组合数学

    ll inv[N], fac[N], facinv[N];
     
    int C(int m, int n) {
        return fac[n] * facinv[m] % mod * facinv[n - m] % mod;
    }
     
    void init() {
        inv[0] = inv[1] = fac[0] = fac[1] = facinv[0] = facinv[1] = 1;
        rep (i, 2, 2e5) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = (mod - mod / i) * inv[mod % i] % mod;
            facinv[i] = facinv[i - 1] * inv[i] % mod;
        }
    }
     
    int main() {
        IOS; init();
        for (cin >> _; _; --_) {
            cin >> n >> k; VI a(n);
            for (auto &i : a) cin >> i;
            sort(all(a), greater<int>());
            int x = 0, y = 0;
            for (int i = k - 1; (~i) && a[k - 1] == a[i]; --i) ++x;
            for (int i = k; i < n && a[i] == a[k - 1]; ++i) ++y;
            cout << C(x, x + y) << '
    ';
        }
        return 0;
    }
    

    F - Unusual Matrix

    跟开关控制上下左右的题一样,

    枚举第一行用不用异或1次, 之后, 第一行的数只能通过或列异或改变, 其他行的数只能通过行异或, 能选择的方式唯一, 判断是否可行即可

    char a[N][N], b[N][N], d[N][N];
     
    bool check() {
        rep (i, 2, n) {
            bool f = d[i][1] ^ b[i][1];
            rep (j, 2, n) if (d[i][j] ^ b[i][j] ^ f) return 0;
        }
        return 1;
    }
     
    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n; bool f = 0;
            rep (i, 1, n) cin >> a[i] + 1;
            rep (i, 1, n) cin >> b[i] + 1;
            memcpy(d, a, sizeof a);
            rep (i, 1, n) if (d[1][i] != b[1][i]) rep (j, 1, n) d[j][i] = d[j][i] == '1' ? '0' : '1';
            f = check();
            memcpy(d, a, sizeof a); rep (i, 1, n) d[1][i] = d[1][i] == '1' ? '0' : '1';
            rep (i, 1, n) if (d[1][i] != b[1][i]) rep (j, 1, n) d[j][i] = d[j][i] == '1' ? '0' : '1';
            f = f | check();
            cout << (f ? "YES
    " : "NO
    ");
        }
        return 0;
    }
    

    G - Strange Beauty

    枚举倍数就好了, nlogn, t <= 10, 总复杂度(O(tnlogn))

    int main() {
        IOS;
        for (cin >> _; _; --_) {
            cin >> n; VI a(2e5 + 1, 0), c(2e5 + 1, 0);
            for (int i = 0; i < n; ++i) cin >> m, ++c[m];
            for (int i = 1; i <= 2e5; ++i) if (c[i]) {
                a[i] += c[i];
                for (int j = i * 2; j <= 2e5; j += i) if (c[j]) umax(a[j], a[i]);
            }
            cout << n - (*max_element(all(a))) << '
    ';
        }
        return 0;
    }
    
  • 相关阅读:
    MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'
    jQuery获取Select选择的Text和 Value(转)
    mybatis3 :insert返回插入的主键(selectKey)
    【转】Mybatis/Ibatis,数据库操作的返回值
    Android问题-打开DelphiXE8与DelphiXE10编译空工程提示“[Exec Error] The command exited with code 1.”
    Android问题-打开DelphiXE8与DelphiXE10新建一个空工程提示"out of memory"
    BAT-使用BAT生成快捷方式
    给 TTreeView 添加复选框
    跨进程发送消息数据
    鼠标拖动虚影效果
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/14328268.html
Copyright © 2020-2023  润新知