跳到正文

个人记录

20240827普及组模拟赛

Gyf117约 10 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 10 分钟

版本

  1. v1当前

20240827普及组模拟赛

复盘

T1

签到题,以后要多练一下签到题和暴力水题的速度.

学习@2huk

%%%

预计分数:100pts100\text{pts} 时间:10min⁡10\min

T2

赛时用sortand\text{and}lower_bound骗分

预计分数:50pts50\text{pts} 时间:50min⁡50\min

T3

一开始手写chk()炸了,后来想拿55pts55\text{pts},致敬不可以,总司令

后来磕了一会用sscanf秒了

预计分数:100pts100\text{pts} 时间:60min⁡60\min

T4

看到题想了一会决定打暴力.

预计分数:30pts30\text{pts} 时间:30min⁡30\min

小结

预计总分数:100+50+100+30=280100 + 50 + 100 + 30 = 280

实际总分数:100+52+100+70=322>280100 + 52 + 100 + 70 = 322 > 280

花费时间:10+50+60+30=150<<21010 + 50 + 60 + 30 = 150 << 210

题解

P7909 [CSP-J 2021] 分糖果

思路

注意到,答案x∈[0,n−1]x \in [0,n-1],我们分类讨论.

  1. ⌊ln⌋≠⌊rn⌋\lfloor\frac{l}{n}\rfloor\ne\lfloor\frac{r}{n}\rfloor ,即∃x∈[l,r]\exists x \in[l,r]满足 x mod n=n−1 \ x\text{ mod } n= n-1,答案为n−1n-1
  2. ⌊ln⌋=⌊rn⌋\lfloor\frac{l}{n}\rfloor=\lfloor\frac{r}{n}\rfloor,即∃x∈[l,r]\exists x \in[l,r]满足r mod n≥x mod n≥l mod nr\text{ mod }n\ge x\text{ mod }n\ge l\text{ mod }n,答案为r mod nr\text{ mod }n
代码
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
ll n, l, r;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> l >> r;
  if(l / n != r / n) {
    cout << n - 1 << endl;
  } else {
    cout << r % n << endl;
  }
  return 0;
}

P7910 [CSP-J 2021] 插入排序

思路

每次直接修改,查询看有几个排在当前元素前面(注:题面给的代码是稳定排序,所以在当前元素前的要加等号).

€€£数据太水了O(nQ)\text{O}(nQ)都能过

代码
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
constexpr ll N = 8000 + 10;
int n, Q;
int a[N];
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> Q;
  for(int i = 1; i <= n; ++i) {
    cin>>a[i];
  }
  for(int q = 1; q <= Q; ++q) {
    int id, x, v;
    cin >> id >> x;
    if(id == 1) {
      cin >> v;
      a[x] = v;
    }
    if(id == 2) {
      int res = 1;
      for(int i = 1;i < x; ++i) {
        res += a[i] <= a[x];
      }
      for(int i = x + 1;i <= n; ++i) {
        res += a[i] < a[x];
      }
      cout << res << '\n';
    }
  }
  return 0;
}

P7911 [CSP-J 2021] 网络连接

思路

用sscanf判断字符串格式,前导00,数字取值.

剩下的一个unordered_map解决.

代码
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
ll n;
unordered_map<string, ll> mp;
ll chk(string s) {
  ll a, b, c, d, e;
  if (sscanf(s.c_str(), "%lld.%lld.%lld.%lld:%lld", &a, &b, &c, &d, &e) != 5) {
    return 0;
  }
  string sa = to_string(a), sb = to_string(b), sc = to_string(c), sd = to_string(d), se = to_string(e);;
  if (sa.size() + sb.size() + sc.size() + sd.size() + se.size() + 4 != s.size()) {
    return 0;
  }
  if (!(0 <= a && a <= 255 && 0 <= b && b <= 255 && 0 <= c && c <= 255 && 0 <= d && d <= 255 && 0 <= e && e <= 65535)) {
    return 0;
  }
  return 1;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    if (!chk(s2)) {
      cout << "ERR" << endl;
      continue;
    }
    if (s1 == "Server") {
      if (mp.count(s2)) {
        cout << "FAIL" << endl;
        continue;
      } else {
        mp[s2] = i;
        cout << "OK" << endl;
        continue;
      }
    }
    if (s1 == "Client") {
      if (mp.count(s2)) {
        cout << mp[s2] << endl;
        continue;
      } else {
        cout << "FAIL" << endl;
        continue;
      }
    }
  }
  return 0;
}

P7912 [CSP-J 2021] 小熊的果篮

思路

ODT秒了

用set模拟块,删后再合并.

代码
C++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
constexpr int N = 2e5 + 10;
int n;
int a[N];
struct node {
  mutable int l, r, v;
  bool operator < (const node b) const {
    return l < b.l;
  }
};
int vis[N];
set<node> s;
int main(){
  cin >> n;
  for (ll i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (ll i = 1; i <= n; ++i) {
    int l = i;
    while (i <= n && a[i] == a[l]) ++i;
    --i;
    s.insert({l, i, a[i]});
  }
  while (s.size()) {
    for (set<node>::iterator it = s.begin(); it != s.end();) {
      while (vis[it->l]) {
        ++it->l;
      }
      cout << it->l << ' ';
      vis[it->l] = 1;
      if (it->l == it->r) {
        set<node>::iterator tmp = it;
        ++it;
        s.erase(tmp);
      } else {
        ++it->l;
        ++it;
      }
    }
    for (set<node>::iterator it = s.begin(); it != s.end();) {
      set<node>::iterator l = it;
      while (it != s.end() && it->v == l->v){
        ++it;
      }
      --it;
      int pl = l->l, pr = it->r, pv = l->v;
      ++ it;
      s.erase(l, it);
      s.insert({pl, pr, pv});
    }
    cout << '\n';
  }
  return 0;
}
原文