2020 年百度之星·程序设计大赛 - 初赛二

海星, 比上次强, 下场初赛就不打了, 主要上次读题太ex, 这次读题海星

A

氵题, 顶多是取整问题有人可能会wa一下(没错, 就是我)

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n >> m >> k;
        int p = m * (100 - k) / 100;
        int c = 0;

        if (p == 0) c = n / m;
        else {
            while (n >= m) {
                int cur = n / m;
                c += cur;
                n = n % m + cur * p;
            }
        }

        cout << c << '\n';
    }
    return 0;
}

B

排序之后, 统一沿着一条直线放就是最优

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;
int a[N];

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n;

        rep (i, 1, n) cin >> a[i];
        sort(a + 1, a + 1 + n);

        ll ans = 0;
        rep (i, 2, n) {
            ans += (ll)(a[i] - a[i - 1]) * (n - i + 1) * (i - 1);
        }

        cout << ans << '\n';
    }
    return 0;
}

C

排完序, 模拟就行

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 2e5 + 5;

int n, m, _, k;
bool v[20005];
pair<int, PII> s[N];

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n;
        memset(v, 0, sizeof v);
        v[1] = 1;
        int cnt = 0;

        rep (i, 1, n) {
            cin >> m;

            rep (j, 1, m) 
                s[++cnt].se.se = i, cin >> s[cnt].fi >> s[cnt].se.fi;
        }

        sort(s + 1, s + 1 + cnt);

        rep (i, 1, cnt) {
            VI cur; cur.pb(s[i].se.se);
            bool f = v[cur.back()];

            while (i < cnt) {
                if (s[i + 1].fi != s[i].fi || s[i + 1].se.fi != s[i].se.fi) break;
                cur.pb(s[++i].se.se);
                if (f) continue;
                f = v[cur.back()];
            }

            if (f) for (int j : cur) v[j] = 1;
        }

        cout << 1;
        rep (i, 2, n) if (v[i]) cout << ' ' << i;
        cout << endl;
    }
    return 0;
}

D

md又是语文题, 原来车牌重复不是相同得车阿, 亏我还set去重了, wa了半天, 还以为自己写错了

就那么点范围, 直接暴搜

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 2e5 + 5;

int n, m, _, k;
int a[10], b[5];

void dfs(int d) {
    if (d > 9) { 
        int c = b[0];
        rep (i, 1, 4) c = max(c, b[i]);
        m = min(m, c);
        return;
    }

    rep (i, 0, 4) {
        b[i] -= a[d];
        dfs(d + 1);
        b[i] += a[d];
    }
}

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n;
        memset(a, 0, sizeof a);

        rep (i, 1, n) {
            string s; cin >> s;
            ++a[s.back() - '0'];
        }

        sort(a, a + 10); m = n;
        rep (i, 0, 4) b[i] = m; 

        dfs(0);
        cout << m << '\n';
    }
    return 0;
}

E

模拟, 对于能现给最喜欢的且能满足所有最喜欢这种饮料得人数, 就先分配

试想: x最喜欢a, 且得到了a, 如果存在用其他饮料跟x换, 使得得分变高, 则x得到了次喜欢得饮料, y得到了a(从喜欢(1)到最喜欢(3)),

还记得前提吗, 我们已经满足了所有最喜欢a得人了, 所以不存在 y, 故能直接满足得,直接先, 剔除这部分人和饮料

那剩下的不就简单了吗? 要么是 两种最喜欢饮料的人群被清除, 或一种最喜欢饮料的人被清除

直接去填补就行了, 模拟一下, 具体细节见代码, 我写的 if else 应该很清晰

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;
int a, b, c, d[3][2];
bool v[3];
char s[5];

void clear(int id, int& a) {
    m += (d[id][0] + d[id][1]) * 3;
    a -= (d[id][0] + d[id][1]);
    d[id][0] = d[id][1] = 0;
    v[id] = 0;
}

void work1(int a, int b, int c, int x, int y) {
    if (a >= x) m += (x << 1) + (a - x);
    else m += (a << 1);

    if (b >= y) m += (y << 1) + (b - y);
    else m += (b << 1);

    m += c * 3;
}

void work2(int b, int x, int y) {
    if (b >= y) m += b * 3 + (x + y - b) * 2;
    else m += b * 3 + (y - b) + (x << 1);
}

int main() {
    IO;
    for (cin >> _; _; --_) {
        cin >> n >> a >> b >> c;
        v[0] = v[1] = v[2] = 1;
        memset(d, 0, sizeof d);

        rep(i, 1, n) {
            cin >> s;

            if (s[0] == '0') {
                if (s[1] == '1') ++d[0][0];
                else ++d[0][1];
            }
            else if (s[0] == '1') {
                if (s[1] == '0') ++d[1][0];
                else ++d[1][1];
            }
            else {
                if (s[1] == '0') ++d[2][0];
                else ++d[2][1];
            }
        }

        m = 0;
        if (a >= d[0][0] + d[0][1]) clear(0, a);
        if (b >= d[1][0] + d[1][1]) clear(1, b);
        if (c >= d[2][0] + d[2][1]) clear(2, c);

        if (!v[0] && !v[1] && !v[2]);
        else if (!v[0] && !v[1]) work1(a, b, c, d[2][0], d[2][1]);
        else if (!v[0] && !v[2]) work1(a, c, b, d[1][0], d[1][1]);
        else if (!v[1] && !v[2]) work1(b, c, a, d[0][0], d[0][1]);
        else if (!v[0]) work2(b, d[1][0], d[1][1]), work2(c, d[2][0], d[2][1]);
        else if (!v[1]) work2(a, d[0][0], d[0][1]), work2(c, d[2][1], d[2][0]);
        else work2(a, d[0][1], d[0][0]), work2(b, d[1][1], d[1][0]);

        cout << m << '\n';
    }
    return 0;
}

F

写了半天, 不会阿, 哭唧唧

猜你喜欢

转载自www.cnblogs.com/2aptx4869/p/13377440.html