跳到正文

个人记录

10.6J组模拟赛

fanhaoyi约 12 分钟
原文
文章信息与版本

文章信息

发布
2026年10月6日
收录
2026年10月6日
更新
2026年11月18日
篇幅
约 12 分钟

版本

  1. v1当前

Problem 1

题面

题面

image.png wtf.png image.png


此题思路十分简单:首先看一下每一场比赛原本可以有多少奖牌,并剩下多少队伍,然后用额外的 mm 支队伍来补全这些剩余量 警钟敲烂:要优先处理剩余量多的,也就是需要补的量最少的;最后m队人所剩下的也要处理\color{red}警钟敲烂:要优先处理剩余量多的,也就是需要补的量最少的;最后 m 队人所剩下的也要处理

AC Code
C++
#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

题面

T2-2.png T2-3.png T2-4.png T2-5.png T2-6.png


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

  • 变量 ti 存储当前有多少步是可以反悔的
  • 变量 cnt 存储当前 “蕈兽” 的数量
  • 变量 at 存储当前所有 “蕈兽” 的攻击力总和\

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


此题在考场上并未AC,只得了 30pts30 pts

WA 30pts30pts Code
错因

考场时未弄清反悔贪心的核心

C++
#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;
}

AC Code
C++
#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

题面

T3.png T3-2.png T3-3.png


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

  • check(x) 函数的意义:是否能达到第 kk 大值
    • 统计有多少性能值大于 kk
    • 枚举这个序列的左端点,看是否能达成目标

注意,此题可以暴力枚举,时间复杂度O(n2log2n)\color{brown}注意,此题可以暴力枚举,时间复杂度 O(n^2 log_2n)
这个思路十分简单,不必多赘述马,代码如下

TLE 45pts45pts Code
C++
#include <iostream>
#include <cstdio>
#include <algorithm>
 
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;
}

AC Code
C++
#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;
}
原文