AtCoder Beginner Contest 319

1|0A - 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; }

2|0B - 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; }

3|0C - False Hope


给定一个3×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; }

4|0D - 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; }

5|0E - Bus Stops


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

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

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/18140240.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示