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

 

 
 
posted @ 2020-08-09 17:21  若讷  阅读(87)  评论(0编辑  收藏  举报