AtCoder Beginner Contest 127 problem-solving report

 

Portal

Very regrettable. That evening a miss. But the feeling will be out of the points of it. Two questions behind partial conclusion title, hit, then should no idea.

 

A - Ferris Wheel

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int a = read(), b = read();
    if (a >= 13) b = b;
    else if (a > 5) b /= 2;
    else b = 0;
    cout << b << '\n';
    return 0; 
}
View Code

 

B - Algae

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int r = read(), d = read(), x = read();
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        printf("%d\n", x);
    }
    return 0;
}
View Code

 

C - Prison

The meaning of problems: there are $ N $ ID card sheets, numbered 1 to $ N $, $ M $ doors, each door corresponding to a range $ \ left [L, R \ right] $, in the closed interval ID card to open the door, asked how many sheets of ID card can open all doors.

Ideas: the equivalent of $ M $ intersection of intervals. Then L is seeking $ $ $ maximum value and the minimum value of R & lt $, $ L greater than $ $ $ R & lt no solution, otherwise $ R - L + 1 $

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int n = read(), m = read();
    int l = 1, r = n;
    while (m--) {
        int u = read(), v = read();
        l = max(l, u); r = min(r, v);
    }
    int ans;
    if (l > r) ans = 0;
    else ans = r - l + 1;
    printf("%d\n", ans);
    return 0;
}
View Code

 

D - Integer Cards

Meaning of the questions: to $ N $ cards, there are $ M $ operations, each can count on up to $ B $ cards into $ C $, asked last $ N $ and the maximum number is the number.

Thinking: certificate may (for example) clear (found), regardless of the final result of the operation sequence.

$ N $ then put into a small number of root stack, and the operation of the size press $ C $ rows, each beginning with the smallest Alternatively, if the minimum value can not change the ratio of the current large $ C $. This ensures that each number once the most out of the team.

Time complexity $ O \ left (n \ log \ left (n \ right) \ right) $ (right?)

#include <bits/stdc++.h>
#define ll long long
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

const int M = 1e5 + 10;

struct P {
    int b;ll c;
    bool operator < (const P &rhs) const {
        return c > rhs.c;      
    }
} p[M];

int main() {
    int n = read(), m = read();
    priority_queue<ll, vector<ll>, greater<ll> > que;
    for (int i = 0; i < n; i++) {
        int x = read();
        que.push((ll)x);
    }    
    for (int i = 0; i < m; i++) p[i].b = read(), p[i].c = (ll)read();
    sort(p, p + m);
    for (int i = 0; i < m; i++) {
        int b = p[i].b;
        if (p[i].c <= que.top()) break;
        while (b--) {
            if (que.top() < p[i].c) {
                que.pop();
                que.push(p[i].c);
            } else {
                break;
            }
        }
    }
    ll sum = 0;
    while (!que.empty()) {
        int x = que.top(); que.pop();
        sum += x;
    }
    cout << sum << '\n';
    return 0;
}
View Code

 

E - Cell Distance

The meaning of problems: seeking a trellis diagram which takes any point $ K $ Manhattan distance and

Thinking: $ N \ times M $ average of any two points inside the trellis diagram Manhattan distance is $ \ dfrac {N + M} {3} $

The answer is $ C ^ {k} _ {N \ times M} C ^ {2} _ {k} \ dfrac {N + M} {3} $

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll MOD = 1e9 + 7;

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

ll qp(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}

const int N = 2e5 + 10;
ll fac[N];

ll C(ll a, ll b) {
    ll ans = fac[a] * qp(fac[b], MOD - 2) % MOD;
    ans = ans * qp((fac[a-b] + MOD) % MOD, MOD - 2) % MOD;
    return ans;
}

int main() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD;
    ll n = read(), m = read(), k = read();
    ll ans = C(n * m, k) * C(k, 2) % MOD * qp(3, MOD - 2) % MOD;
    ans = Years * (n + m)% MOD; 
    years % = MOD; 
    cout << years << ' \ n ' ;
    return  0 ; 
}
View Code

 

F - Absolute Minima

Meaning of the questions: have the function $ f \ left (x \ right) $ 0 initial, two operations, one is for $ f \ left (x \ right) $ plus $ \ left | xa \ right | + b $, 2 is a function of the minimum asking and $ x $

Thinking: certificate may (for example) clear (found), the minimum value of a function of a certain median $ A $ sequence to take.

Two priority queues, a descending ascending a, $ A $ was added per two queue are added, in comparison to their top, the top must be less than or equal descending ascending top, so that two stacks can be achieved are stored sequence the left and right halves.

At the same time, it is taken to the top of the descending order of $ X $

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int q = read();
    priority_queue<int> l;
    priority_queue<int, vector<int>, greater<int> > r;
    long long ans = 0;
    while (q--) {
        int t = read();
        if (t == 1) {
            int a = read(), b = read();
            ans += b;
            l.push(a);
            r.push(a);
            if (l.top() > r.top()) {
                int x = l.top(); l.pop();
                int y = r.top(); r.pop();
                ans += abs(x - y);
                l.push(y); r.push(x);
            }
        } else {
            printf("%d %lld\n", l.top(), ans);
        }
    }
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Mrzdtz220/p/10937591.html