Educational Codeforces Round 21

Educational Codeforces Round 21

https://codeforces.com/contest/808
苯比只会ABC,呜呜,

A. Lucky Year

被pow()坑了

#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll pw[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};

int main () {
    ll n;
    cin >> n;
    string s = to_string (n);
    //cout << s << endl;
    int x = s[0] - '0' +  1;
    cout << (ll)(x * pw[s.size () - 1] - n);
}

//len: 1-9

B. Average Sleep Time

如题

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 2e5 + 5;
ll a[N];

int main () {
    int n, k;
    cin >> n >> k;
    ll sum = 0;
    for (int i = 1; i <= n; i++)    cin >> a[i], a[i] += a[i-1];
    for (int i = k; i <= n; i++)    sum += a[i] - a[i - k];
    cout << fixed << setprecision (9) << 1.0 * (sum) / (n - k + 1);
}

C. Tea Party

细节模拟

#include <bits/stdc++.h>
#define ll long long

using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 5;
ll a[N], n, sum, maxsum, base;
int ans[N];
pii v[N];

int main () {
    cin >> n >> sum;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        v[i] = {x, i};
        base += (x + 1) / 2;
        maxsum += x;
    }
    if (sum < base || maxsum < sum) {
        cout << -1 << endl;
        return 0;
    }
    sum -= base;
    sort (v + 1, v + n + 1, greater <pii>());
    //前面贪心塞满
    //cout << sum << endl;
    for (int i = 1; i <= n; i++) {    
        if (sum <= 0) {
            for (int j = i; j <= n; j++)     ans[v[j].second] = (v[j].first + 1) / 2;
            break;
        }
        int x = v[i].first, id = v[i].second;
        //cout << x << ' ' << id << ' ';
        ans[id] = (x + 1) / 2;
        if (sum >= x / 2)   ans[id] = x, sum -= (x / 2); //装满
        else    ans[id] += sum, sum = 0;
        //cout << sum << endl;
    }
    for (int i = 1; i <= n; i++)     cout << ans[i] << ' ';
}

D. Array Division

没审清楚题目!!只能移动一次,直接map就好,要注意若干个爆int的地方

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 100005;
ll a[N], n;
ll sum, cur;

int main () {
    int n;
    cin >> n;
    map<ll, int> pre, suf; //记录出现的数
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
        suf[a[i]] ++;
    }
    if (sum & 1) {
        cout << "NO";
        return 0;
    }
    sum /= 2;
    
    for (int i = 1; i <= n; i++) {
        cur += a[i];
        if (cur == sum) {
            cout << "YES\n";
            return 0;
        }
        pre[a[i]] ++, suf[a[i]] --;
        ll dx = abs (cur - sum);
        if ((cur > sum && pre[dx]) || (cur < sum && suf[dx])) {
            cout << "YES\n";
            return 0;
        }    
    }
    cout << "NO\n";
}

//能否分成两段相等的和
//sum已知
//只能移动一次!!!

E. Selling Souvenirs

F. Card Game

G. Anthem of Berland

posted @ 2023-02-22 21:34  Sakana~  阅读(5)  评论(0编辑  收藏  举报