Codeforces Round # 577 (Div. 2) solution to a problem

Game link: https://codeforc.es/contest/1201

A. Important Exam
meaning of the questions: There \ (n \) individuals, each person is given \ (m \) answers, each answer has a score \ (a_i \) , the correct answer to each question is uncertain, ask how much is the maximum possible score.

Analysis: The maximum number of greedy enough for each question.

AC Code:

#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
int n, m, t; 
string s;
map<char, int>mp[1005];
int main() {
    io(); cin >> n >> m;
    rep(i, 1, n) {
        cin >> s;
        rep(j, 0, s.length() - 1) {
            mp[j + 1][s[j] - 'a']++;
        }
    }
    ll ans = 0;
    rep(i, 1, m) {
        cin >> t;
        int maxx = 0;
        for (auto it : mp[i]) {
            maxx = max(maxx, it.second);
        }
        ans += 1ll * maxx * t;
    }
    cout << ans;
}

 
B. Zero Array
meaning of the questions: given a \ (n-\) series number, wherein each operation of any two numbers can \ - (1 \) is zero, this will be asked whether all columns Save.

Analysis: First, as a total of 2 per reduced, and thus is not an odd number of columns. And consider the even number columns, find if and only if there is no maximum value is greater than half the sum of the number of columns.

AC Code:

#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
int n, m, t; 
ll a[SIZE];
int main() {
    io(); cin >> n;
    ll sum = 0;
    rep(i, 1, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a + 1, a + 1 + n);
    if (sum & 1) { cout << "NO"; return 0; }
    else {
        if (a[n] > sum / 2)cout << "NO";
        else cout << "YES";
    }
}

 
C. Maximum Median
that Italy: Given a \ (n-\) the number of columns and the number of \ (K \) operations, each time a count column can \ (1 + \) . Ask \ (k \) the maximum number of operations after a median column is how much. ( \ (N-\) is an odd number)

Analysis: The first sorted and then to the median maximum, we apparently only after the logarithmic number of columns in the median and the median current operation. So we consider greedy to add the following example:

7 7
1 2 3 4 5 6 10

Step: 12355610

Step Two: 12366610

The third step: 12377810

This greedy constructed by means of a prefix and similar ideas can be realized, AC codes:

#include <bits/stdc++.h>
#define SIZE 500007
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef long long ll;
void io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
int n, m, t, k;
ll a[SIZE], pre[SIZE];
int main() {
    io(); cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    sort(a + 1, a + 1 + n);
    rep(i, (n + 3) / 2, n) {
        pre[i] = pre[i - 1] + (i - (n + 1) / 2) * (a[i] - a[i - 1]);
        if (pre[i] > k) {
            ll tmp = ((k - pre[i - 1]) / (i - (n + 1) / 2));
            cout << a[i - 1] + tmp;
            return 0;
        }
    }
    ll tmp = (k - pre[n]) / ((n + 1) / 2);
    cout << tmp + a[n];
}

 
D problem in the afternoon finished school more than write it. . .

Guess you like

Origin www.cnblogs.com/st1vdy/p/11301560.html