Educational Codeforces Round 79 (Rated for Div. 2)

题目链接

B:
水题,从头累加,超过s时输出遍历过的最大值的位置即可

C:
读懂题也是水题,记录当前最大的下标与已经去掉的数量,维护即可

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;



void run_case() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1), b(m+1);
    for(int i = 1; i <= n; ++i) {
        int t; cin >> t;
        a[t] = i;
    }
    for(int i = 1; i <= m; ++i) {
        cin >> b[i];
    }
    LL ans = 0, sum = 0, pre = 1;
    for(int i = 1; i <= m; ++i) {
        int pos = a[b[i]];
        if(pos <= pre) ans++, sum++;
        else {
            ans += (pos - sum - 1) *2 + 1;
            pre = pos;
            sum++;
        }
    }
    cout << ans << "
";

}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    int t; cin >> t;
    while(t--)
    run_case();
    cout.flush();
    return 0;
}

D:
简单的概率+逆元题
设选择第(i)个人,他有(k_i)种选择,每种选择对应的人的总个数为(包括自己)(x_{k_{i_j}}), 答案为(sum_{i=1}^{n}{frac{1}{n}sum_{j=1}^{k_i}(frac{1}{k_i} frac{x_{k_{i_j}}}{n})}), 化简求和,为:(frac{1}{n^2}sum_{i=1}^{n}{sum_{j=1}^{k_i}(frac{1}{k_i}x_{k_{i_j}})})

#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const LL MOD = 998244353;
const int maxn = 1e6+5;

LL inv[maxn];

void init() {
    inv[1] = 1;
    for(int i = 2; i < maxn; ++i)
        inv[i] = (MOD - MOD / i) * 1LL * inv[MOD%i] % MOD;
}

void run_case() {
    init();
    int n; cin >> n;
    vector<LL> b[n], c(maxn);
    for(int i = 0; i < n; ++i) {
        int t; cin >> t;
        for(int j = 0; j < t; ++j) {
            int k; cin >> k;
            b[i].push_back(k);
            c[k]++;
        }
    }
    LL ans = 0;
    for(int i = 0; i < n; ++i) {
        int k = b[i].size();
        for(int j = 0; j < k; ++j) {
            (ans += inv[k]*c[b[i][j]] % MOD) %= MOD;
        }
    }
    ans = (ans * inv[n] % MOD * inv[n]) % MOD;
    ans = (ans + MOD) % MOD;
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}
原文地址:https://www.cnblogs.com/GRedComeT/p/13062702.html