10.6J组模拟赛

· · 个人记录

Problem 1

题面

::::info[题面] ::::

此题思路十分简单:首先看一下每一场比赛原本可以有多少奖牌,并剩下多少队伍,然后用额外的 m 支队伍来补全这些剩余量

\color{red}警钟敲烂:要优先处理剩余量多的,也就是需要补的量最少的;最后 m 队人所剩下的也要处理

::::success[AC Code]

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int N = 1e2 + 5;
ll n, k, x[N], m, ans;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> x[i], ans += (x[i] / k), x[i] %= k;
    sort(x + 1, x + n + 1);
    cin >> m;
    for (int i = n; i >= 1; i--) {//根据需要补的量排序
        if (m + x[i] >= k) m -= (k - x[i]), ans++;
        else break;
    }
    ans += (m / k);//千万别忘了这个!!!
    cout << ans;
    return 0;
}

::::

Problem 2

::::info[题面] ::::

此题为反悔贪心,核心为以下几点:

最后按题目要求输出 这应该没人不会吧\

\color{red}

此题在考场上并未AC,只得了 30 pts ::::error[WA 30pts Code] :::warning[错因] 考场时未弄清反悔贪心的核心 :::

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int N = 1e6 + 5;
int n, op[N], cnt = 1, at = 1, sum;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> op[i];
        if (op[i] == 1) cnt++, at++;
        else if (op[i] == -1) cnt--;
        else sum++;
        if (cnt + sum < 0 || (op[i] == -1 && cnt + sum <= 0)) {
            cout << -1;
            return 0;
        } 
    }
    int tmp = min(sum, (cnt + sum) / 2);
    cnt -= tmp;
    cnt += (sum - tmp);
    at += (sum - tmp);
    cout << at << ' ' << cnt << endl;
    int gt = __gcd(cnt, at);
    cnt /= gt;
    at /= gt;
    cout << at << ' ' << cnt; 
    return 0;
}

::::

::::success[AC Code]

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;

int n, at = 1, cnt = 1, ti;
bool flag = false;

int main() {
//  ios::sync_with_stdio(false);
//  cin.tie(0), cout.tie(0);
//  freopen("t2.in", "r", stdin);
//  freopen("NO78.out", "w", stdout);
    cin >> n;
    while (n--) {
        int op;
        cin >> op;
        if (op == 1) at++, cnt++;
        else if (op == -1) {
            if (cnt > 1) cnt--;
            else if (ti >= 1) ti--, at++, cnt++;
            else {
                cout << -1;
                return 0;
            }
        }
        else {
            if (cnt > 1) ti++, cnt--;
            else at++, cnt++;
        }
    }
    int gt = __gcd(at, cnt);
    at /= gt, cnt /= gt;
    cout << at << ' ' << cnt;

    return 0;
}

::::

Problem 3

::::info[题面] ::::

此题为二分,需要对第 k 大值进行二分,需要注意的是以下几点

using namespace std; using ll = long long; using ull = unsigned long long;

const int N = 2e5 + 5; ll n, k, m, c, d, x[N], tmp[N], ans;

int main() { // ios::sync_with_stdio(false); // cin.tie(0), cout.tie(0); // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n >> k >> m >> c >> d; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= n - m + 1; i++) { for (int j = 1; j <= n; j++) tmp[j] = x[j]; for (int j = 0; j < m; j++) tmp[i + j] += (c + d * j); sort(tmp + 1, tmp + n + 1); ans = max(ans, tmp[n - k + 1]); } cout << ans; return 0; }


::::
*****
::::success[AC Code]
```cpp line-numbers
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int N = 2e5 + 5;
ll n, k, m, c, d, x[N], dp[N], ans;

bool check(ll mid) {
    ll cnt = 0;
    for (auto i : x) cnt += (i >= mid ? 1 : 0);
    if (cnt >= k) return true;

    memset(dp, 0, sizeof(dp));

    for (ll i = 1; i <= n; i++) {
        if (x[i] < mid) {
            ll r = min(m - 1, i - 1);
            ll maxn = x[i] + c + d * r;
            if (maxn < mid) continue;
            dp[max(m, i)]++;
            ll minn = x[i] + c;
            if (minn >= mid) dp[min(n + 1, i + m)]--;
            else {
                ll tmp = mid - x[i] - c, ps;
                if (tmp % d == 0) ps = tmp / d - 1;
                else ps = tmp / d;
                dp[min(n + 1, i + m - ps - 1)]--;
            }
        }

    }

    for (int i = m; i <= n; i++) {
        dp[i] += dp[i - 1];
        if (dp[i] + cnt >= k) return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> k >> m >> c >> d;
    for (int i = 1; i <= n; i++) cin >> x[i];
    ll l = 0, r = 1e15;
    while (l <= r) {
        ll mid = l + r >> 1;
        if (check(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << ans;
    return 0;
}

::::