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

Game link : https://codeforc.es/contest/1199
 
A. City Day
meaning of the questions: given a number of columns, and two integers \ (the X-, the y-\) , asked to find the serial number of the foremost figures \ (d \ ) , such that \ (D \) satisfies \ (a_d is <a_j \) ( \ (DX \ Leq J <D \) && \ (D <J \ Leq D + Y \) ).

Analysis: Because x and y are less than 7, so you can direct violence.

AC Code:

#include <bits/stdc++.h>
#define SIZE 200007
#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);
}
ll n, x, y, a[SIZE];
int main() {
    io();
    cin >> n >> x >> y;
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n) {
        bool flag = 1;
        for (int k = i - 1, cnt = 1; k > 0 && cnt <= x; k--, cnt++) {
            if (a[k] <= a[i]) { flag = 0; break; }
        }
        for (int k = i + 1, cnt = 1; k <= n && cnt <= y; k++, cnt++) {
            if (a[k] <= a[i]) { flag = 0; break; }
        }
        if (flag) { cout << i << endl; return 0; }
    }
}

 
B. Water Lily

Analysis: Geometry water problems, like push equations.

AC Code:

#include <bits/stdc++.h>
using namespace std;
int main() {
    double l, h;
    cin >> h >> l;
    double s = (l * l - h * h) / 2 / h;;
    printf("%.12lf", s);
}

 
C. MP3
meaning of the questions: If there is an array \ (K \) different number, each number is space \ (k = log_2K \) , which set the number of total memory is \ (NK \) , you have the ability to change the size of a number of less than \ (L \) can be changed to \ (L \) is greater than \ (R & lt \) can be changed to \ (R & lt \) , the total memory is now given, find the least number of changes.

Analysis: First find the deposit up to \ (k \) number, then we obviously use \ (map \) to record the data, then \ (map \) before the \ (k \) the number and after the k thrown into a number of two-way queue (because we remove at least \ (k \) number, and that \ (k \) number only in the header or trailer), this \ (2k \) the number of prefixes and demand, in each k is obtained in the minimum number.

AC Code:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define SIZE 400007
#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);
}
ll n, I, a[SIZE], pre[SIZE];
map<ll, ll> mp;
deque<pair<ll, ll> > q;
int main() {
    io(); cin >> n >> I;
    rep(i, 1, n) {
        cin >> a[i];
        ++mp[a[i]];
    }
    ll k = 0; I *= 8;   //用k记录最多存储几个数
    while (1ll * ceil(log2(mp.size() - k))* n > I) k++;
    auto it = mp.begin();
    auto itr = mp.rbegin();
    rep(i, 1, k) {
        q.push_back(make_pair(it->first, it->second));
        q.push_front(make_pair(itr->first, itr->second));
        it++, itr++;
    }
    auto itx = q.begin();
    rep(i, 1, q.size()) pre[i] = pre[i - 1] + itx++->second;
    ll sum = INF;
    rep(i, k, 2 * k) sum = min(sum, pre[i] - pre[i - k]);
    cout << sum;
}

 
D. Welfare State
that Italy: Given a \ (n-\) number of columns and two operations. First, the operation of the serial number \ (P \) is modified to a digital \ (X \) , the second is to operate less than all \ (X \) is modified to a digital \ (X \) . The final output of the series.

Analysis: At first glance like a tree line, but will \ (T \) (Do not ask how I know), in fact, a direct fucks before. We found that for the first operation and the second operation we need only consider the kind of large, thus opening two arrays, \ (b \) array a save operation, \ (maxx \) array saving operation two, finally taking \ (max \) output can be.

AC Code:

#include<bits/stdc++.h>
#define SIZE 200007
#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);
}
ll n, m, a[SIZE], b[SIZE], sig, maxx[SIZE], pos;
int main() {
    io(); cin >> n;
    rep(i, 1, n) cin >> a[i];
    cin >> m;
    rep(i, 1, m) {
        cin >> sig;
        if (sig == 1) {
            cin >> pos;
            cin >> a[pos];
            b[pos] = i;
        }
        else cin >> maxx[i];
    }
    for (int i = m; i; --i) maxx[i - 1] = max(maxx[i - 1], maxx[i]);
    rep(i, 1, n) cout << max(a[i], maxx[b[i]]) << ' ';
}

 
E. Matching vs Independent Set
题意:

Guess you like

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