AtCoder Beginner Contest 319

A - Legendary Players

#include<bits/stdc++.h>

using namespace std;

int main() {
    map<string, string> h;
    h["tourist"] = "3858";
    h["ksun48"] = "3679";
    h["Benq"] = "3658";
    h["Um_nik"] = "3648";
    h["apiad"] = "3638";
    h["Stonefeang"] = "3630";
    h["ecnerwala"] = "3613";
    h["mnbvmar"] = "3555";
    h["newbiedmy"] = "3516";
    h["semiexp"] = "3481";
    string s;
    cin >> s;
    cout << h[s] << "\n";
    return 0;
}

B - Measure

#include<bits/stdc++.h>

using namespace std;

int main() {
    map<string, string> h;
    int n;
    cin >> n;
    for (int i = 0, f; i <= n; i++) {
        f = 1;
        for( int j = 1 ; f and j <= 9 ; j ++ ){
            if( n % j ) continue;
            if( i % ( n / j ) ) continue;
            cout << j , f = 0;
        }
        if(f) cout << "-";
    }
    return 0;
}

C - False Hope

给定一个\(3\times 3\)的矩阵,保证任意行、列、对角线不会出现三个相同的情况。一开始,矩阵为空,每次可以随机的填入一个数,如果出现任意行、列、对角线填入的前两个值相同,就会失望。问不失望的概率。

因为这道题目的填入顺序只有\(9!\)种,所以可以暴力的枚举,然后检查就好了。

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

using vi = vector<int>;


int main() {
    vi a(9), b(9);
    for (auto &i: a) cin>> i;
    iota(b.begin(), b.end(), 0);
    vector<vi> l = {{0, 1, 2},
                    {3, 4, 5},
                    {6, 7, 8},
                    {0, 3, 6},
                    {1, 4, 7},
                    {2, 5, 8},
                    {0, 4, 8},
                    {2, 4, 6}};

    double x = 0, y = 0;
    do {
        int ok = 1;
        for (const auto li: l) {
            vi f;
            for (const auto &i: b)
                if (ranges::count(li, i)) f.push_back(a[i]);
            if( f[0] == f[1] ) ok = 0;
        }
        x += ok, y += 1;
    } while (next_permutation(b.begin(), b.end()));
    cout << fixed << setprecision(20) << x / y << "\n";
    return 0;
}

D - Minimum Width

二分答案,然后\(O(n)\)的check一下

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64

using vi = vector<int>;

const i64 inf = 1e15;

i32 main() {
	ios::sync_with_stdio(false) , cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	vi a(n);
	for(auto &i : a) cin >> i;
	int l = ranges::max(a) , r = inf, res = -1;
	auto check = [=](int x) -> bool {
		int cnt = 0 , used = x;
		for(const auto &i : a){
			if(used + 1 + i > x) cnt ++ , used = i;
			else used += 1 + i;
		}
		return cnt <= m;
	};

    while(l <= r){
    	int mid = (l + r) / 2;
    	if( check(mid) ) res = mid, r = mid - 1;
    	else l = mid + 1;
    }
    cout << res << "\n";
    return 0;
}

E - Bus Stops

值得注意的一点就是,每个公交车只能从\(i\)走到\(i+1\),这样的话求出\(P_i\)的最小公倍数,然后枚举出所有的情况即可。

#include<bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64

using vi = vector<int>;
using pii = pair<int,int>;

const i64 inf = 1e15;

i32 main() {
	ios::sync_with_stdio(false) , cin.tie(nullptr);
	int n, x, y;
	cin >> n >> x >> y , n --;
	vector<pii> city(n);
	int d = 1;
	for(auto &[p,t] : city) cin >> p >> t , d = lcm(d , p);
	vi dis(d);
	for( int i = 0 ; i < d ; i ++ ){
		dis[i] = i + x;
		for(const auto &[p,t] : city){
			while(dis[i] % p) dis[i] ++;
			dis[i] += t;
		}
		dis[i] += y - i;
	}
    int q;
    cin >> q;
    for(int x ; q ; q --){
    	cin >> x;
    	cout << x + dis[x%d] << "\n";
    }
    return 0;
}
posted @ 2024-04-17 11:43  PHarr  阅读(4)  评论(0编辑  收藏  举报