区间合并
AC代码:
#include <iostream> #include <cstdio> #include <queue> #include <deque> #include <stack> #include <string> #include <cstring> #include <numeric> #include <functional> #include <cstdlib> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; //head int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<LL, LL>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; LL tmp = a[i].first; a[i].first = a[i].first - a[i].second; a[i].second = tmp + a[i].second; } sort(a.begin(), a.end(), [&](pair<LL, LL> a, pair<LL, LL> b) { if (a.first != b.first) { return a.first < b.first; } return a.second < b.second; }); LL ans = 0; LL r = a[0].second; for (int i = 1; i < n; i++) { if (a[i].first > r) { ans += a[i].first - r; r = a[i].second; } else { r = max(r, a[i].second); } } cout << ans << '\n'; return 0; }
数学几何题
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; const double PI = acos(-1.0); void Solve() { double r, xq, yq, d; cin >> r >> xq >> yq >> d; double zhouchang = 2 * PI * r; double len = sqrt(xq * xq + yq * yq); double c = len + d; double x = len - d; double now1 = acos(c / r); double now2 = acos(x / r); double now3 = now1 > now2 ? now1 - now2 : now2 - now1; cout << fixed << setprecision(9) << zhouchang * now3 / PI / 2 << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { Solve(); } return 0; }
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int len = s.size(); int cnt = 0; for (int i = 0; i < len; i++) { if (s[i] == '9') { cnt++; } else { break; } } if (cnt >= len - 1) { cout << s <<'\n'; } else { for (int i = 0; i < len - 1; i++) { cout << 9; } cout << '\n'; } return 0; }
概率期望DP+逆元
AC代码:
#include <bits/stdc++.h> using namespace std; using LL = long long; const LL mod = 1e9 + 7; LL dp[150][30]; LL qp(LL a, LL b, LL res) { for (; b; b >>= 1, a = a * a % mod) { if (b & 1) { res = res * a % mod; } } return res % mod; } LL inv(LL x, LL y) { return qp(x, mod - 2, y); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); //1.没摸到 2.四张全摸到 for (int i = 1; i <= 4 * 34 - 13; i++) { for (int j = 1; j <= 13; j++) { if (i < 3 * j) { continue; } LL iinv = inv(i, 3 * j); if (j == 1) { dp[i][j] = (1 + dp[i - 1][j] * (1 + mod - iinv)) % mod; } else { dp[i][j] = (1 + dp[i - 1][j] * (1 + mod - iinv) + dp[i - 1][j - 2] * iinv) % mod; } } } int T; cin >> T; for (int j = 1; j <= T; j++) { string s; cin >> s; map<string, int> mp; for (int i = 0; i < 26; i += 2) { string x = ""; x += s[i]; x += s[i + 1]; mp[x]++; } int ans = 0; for (auto it : mp) { if (it.second == 2) { ans++; } } cout << "Case #" << j << ": " << dp[4 * 34 - 13][13 - 2 * ans] << '\n'; } return 0; }
“蔚来杯“2022牛客暑期多校训练营1 A、D、G、I
于 2022-07-26 16:38:05 首次发布