流媒体播放器 Takahashi 决定从 L 点钟到 R 点钟(使用 24 小时钟)进行流媒体播放。
他有 N 个听众,其中 i 个听众可以收听 Xi 点到 Yi 点的流媒体节目。
有多少听众可以从头到尾收听高桥的节目?
思路
高桥就是个流媒体播放器(((怒怒怒
没错这个题面翻译来自deepl不代表本博客立场
水
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include<bits/stdc++.h> usingnamespace std; intmain() { int n, l, r; cin >> n >> l >> r; int ans = 0; while (n--) { int x, y; cin >> x >> y; ans += (x <= l && y >= r); } cout << ans; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long signedmain() { int n; cin >> n; string ans; ans.clear(); int cnt = 0; while (n--) { char s; int x; cin >> s >> x; if (cnt + x > 100) { cout << "Too Long"; return0; } cnt += x; while (x--) { ans = ans + s; } } cout << ans; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long int a, n; int ans = 0; boolcheck(int x) { string tp; tp.clear(); while (x) { tp += ((x % a) + '0'); x /= a; } string ttp = tp; reverse(tp.begin(), tp.end()); return ttp == tp; } intto10(string x) { int res = 0; for (int i = 0; i < x.length(); i++) { res = (res * 10) + (x[i] - '0'); } return res; } voiddfs(string s, int x) { if (x == -1) { return; } string tp = s; reverse(tp.begin(), tp.end()); string ttp = s + tp; int a = to10(ttp); if (a <= n && check(a)) { ans += a; } tp.erase(0, 1); ttp = s + tp; a = to10(ttp); if (a <= n && check(a)) { ans += a; }
if (s.empty()) { for (char i = '1'; i <= '9'; i++) { dfs(s + i, x - 1); } } else { for (char i = '0'; i <= '9'; i++) { dfs(s + i, x - 1); } } } voidsolve(int x) { string tp; tp.clear(); dfs(tp, x); } signedmain() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> n; int tp = n, cnt = 0; while (tp) { cnt++; tp /= 10; } solve((cnt + 1) / 2); cout << ans; return0; }
D. Transmission Mission
题目描述
在一条数线上有 N 座房子,编号从 1 到 N 。房子 i 位于坐标 Xi 。同一坐标上可能有多个房屋。
在数线上的任意实数坐标上放置 M 基站。然后,为每个基站设置一个非负整数信号强度。
当基站的信号强度设置为 x 时,当且仅当基站与房屋之间的距离最多为 2x 时,该基站的信号才能到达房屋。特别是当 x=0 时,信号只能到达与基站位于同一坐标上的房屋。
#include<bits/stdc++.h> usingnamespace std; #define int long long signedmain() { int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (m == n) { cout << 0 << '\n'; return0; } sort(a.begin(), a.end()); vector<int> b; for (int i = 1; i < n; i++) { b.push_back(a[i] - a[i - 1]); } sort(b.rbegin(), b.rend()); int cnt1 = a.back() - a.front(); int cnt2 = 0; for (int i = 0; i < m - 1; i++) { cnt2 += b[i]; } cout << cnt1 - cnt2 << '\n'; return0; }
#include<bits/stdc++.h> usingnamespace std; #define int long long constint mod = 998244353; int n; intfastpow(int a, int b){ int res = 1; while (b) { if (b & 1) { res = (res * a) % mod; } a = (a * a) % mod; b >>= 1; } return res; } signedmain() { cin >> n; int cnt = 0; for (int l = 1, r; l <= n; l = r + 1) { r = n / (n / l); int q = n / l; if (q <= n / q) { cnt = (cnt + ((r - l + 1) % mod) * (q % mod)) % mod; } else { for (int i = l; i <= r; ++i) { cnt = (cnt + (n / i) % mod) % mod; } } }
int ans = 0; ans = (ans + (((n % mod) * ((n + 1) % mod)) % mod * fastpow(2, mod - 2)) % mod) % mod; ans = (ans - cnt) % mod; if (ans < 0) { ans += mod; } cout << ans; return0; }