• Codeforces Round #648 (Div. 2)


    题目传送门

    A. Matrix Game

    判断一下min(空行个数,空列个数)为奇数还是偶数

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
     
    int n, m;
    int mp[60][60];
    int usex[60], usey[60];
    int cntx, cnty;
    inline void solve(int T)
    {
        cin >> n >> m;
        rep(i, 1, n) usex[i] = 0;
        rep(j, 1, m) usey[j] = 0;
        rep(i, 1, n) rep(j, 1, m)
        {
            cin >> mp[i][j];
            if (mp[i][j])
                usex[i] = usey[j] = 1;
        }
        cntx = cnty = 0;
        rep(i, 1, n) if (!usex[i]) cntx++;
        rep(j, 1, m) if (!usey[j]) cnty++;
        puts(min(cntx, cnty) % 2 == 0 ? "Vivek" : "Ashish");
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
     
        int T = 1;
        cin >> T;
        rep(i, 1, T) solve(i);
    }
    View Code

    B. Trouble Sort

    如果有0或1,怎么交换都行

    如果全是0或全是1,那么就不能交换,判断一下初始排序是否符合要求

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
     
    int n, cnt, a[510], b[510], flag;
    inline void solve(int T)
    {
        cnt = flag = 0;
        cin >> n;
        rep(i, 1, n) cin >> a[i];
        rep(i, 1, n) cin >> b[i], cnt += b[i];
        flag = 1;
        rep(i, 1, n - 1) if (a[i] > a[i + 1]) flag = 0;
        if (cnt != 0 && cnt != n)
            flag = 1;
        puts(flag ? "Yes" : "No");
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
     
        int T = 1;
        cin >> T;
        rep(i, 1, T) solve(i);
    }
    View Code

    C. Rotation Matching

    记录每个b[i]与a[i]配对需要移动的次数

    取数量最大的次数

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
     
    int n, a[200010], b[200010];
    int wz[200010], cnt[200010], ans;
    inline void solve(int T)
    {
        cin >> n;
        rep(i, 1, n) cin >> a[i], wz[a[i]] = i;
        rep(i, 1, n) cin >> b[i], cnt[(wz[b[i]] + n - i) % n]++;
        rep(i, 0, n - 1) ans = max(ans, cnt[i]);
        cout << ans << endl;
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
     
        int T = 1;
        // cin >> T;
        rep(i, 1, T) solve(i);
    }
    View Code

    E. Maximum Subsequence Value

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define rep(i, a, b) for (register int i = a; i <= b; i++)
     
    ll n, a[510];
    ll ans;
    inline void solve(int T)
    {
        cin >> n;
        rep(i, 1, n) cin >> a[i];
        rep(i, 1, n) rep(j, 1, n) rep(k, 1, n) ans = max(ans, a[i] | a[j] | a[k]);
        cout << ans << endl;
    }
    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
     
        int T = 1;
        // cin >> T;
        rep(i, 1, T) solve(i);
    }
    View Code
     
     
  • 相关阅读:
    bzoj1477: 青蛙的约会
    数论/the second wave
    bzoj2818: Gcd
    bzoj2705: [SDOI2012]Longge的问题
    数论/the first wave
    bzoj3942: [Usaco2015 Feb]Censoring
    BZOJ 1059: [ZJOI2007]矩阵游戏( 匈牙利 )
    BZOJ 1013: [JSOI2008]球形空间产生器sphere( 高斯消元 )
    BZOJ 1823: [JSOI2010]满汉全席( 2-sat )
    BZOJ 4260: Codechef REBXOR( trie )
  • 原文地址:https://www.cnblogs.com/likunhong/p/13463590.html
Copyright © 2020-2023  润新知