ABC319

发布时间 2023-09-15 02:40:20作者: V_Melville

T1:Legendary Players

模拟

代码实现
table = '''
tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481
'''

s = input()
for line in table.strip().split('\n'):
    user, rating = line.split()
    if user == s:
        print(rating)

T2:Measure

模拟

代码实现
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    string s(n+1, '-');
    for (int j = 9; j >= 1; --j) {
        if (n%j != 0) continue;
        for (int i = 0; i <= n; i += n/j) {
            s[i] = '0'+j;
        }
    }
    
    cout << s << '\n';
    
    return 0;
}

T3:False Hope

简单题意:

现在有一个 \(3 \times 3\) 的方格 \(c\),每一个格子中有一个元素,但是刚开始你不知道所有方格中权值的情况。

现在你将要进行 \(9\) 次操作,每一次操作你将要选择一个没有被翻开的位置。

如果在一次操作中,在将要翻转的格子的横向或纵向或对角线上已经有两个已经翻开的格子并且满足同一方向上有两个格子上的数相同,那么你就会感到沮丧。

求:以任意顺序翻开所有格子,你不会感到沮丧的概率。

分析:

暴力枚举 \(9!\) 种顺序即可

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using P = pair<int, int>;

int main() {
    vector<int> c(9);
    rep(i, 9) cin >> c[i];
    
    vector<int> p(9);
    rep(i, 9) p[i] = i;
    
    int cnt = 0, tot = 0;
    do {
        bool ok = true;
        auto f = [&](int i, int j, int k) {
            vector<P> d;
            d.emplace_back(p[i], c[i]);
            d.emplace_back(p[j], c[j]);
            d.emplace_back(p[k], c[k]);
            sort(d.begin(), d.end());
            if (d[0].second == d[1].second) ok = false;
        };
        f(0, 1, 2);
        f(3, 4, 5);
        f(6, 7, 8);
        f(0, 3, 6);
        f(1, 4, 7);
        f(2, 5, 8);
        f(0, 4, 8);
        f(2, 4, 6);
        if (ok) cnt++;
        tot++;
    } while (next_permutation(p.begin(), p.end()));
    
    double ans = 1.*cnt/tot;
    printf("%.10f\n", ans);
    
    return 0;
}