#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) int n, m, k; void solve() { cin >> n >> m >> k; if (m <= n / k) cout << m << endl; else cout << n / k - ceil(1.0 * (m - n / k) / (k - 1)) << endl; } int main() { int t = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) int n, m, x, y, ans; char mp[1010]; void solve() { cin >> n >> m >> x >> y; ans = 0; rep(i, 1, n) { cin >> mp + 1; if (y >= 2 * x) rep(j, 1, m) { if (mp[j] == ‘.‘) ans += x; } else rep(j, 1, m) if (mp[j] == ‘.‘) { if (mp[j + 1] == ‘.‘) ans += y; else ans += x; j++; } } cout << ans << endl; } int main() { int t = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for (register int i = a; i <= b; i++) ll c, h, t; void solve() { cin >> h >> c >> t; if (h == t) { puts("1"); return; } if (h + c >= 2 * t) { puts("2"); return; } ll l = 1, r = 1000000; while (l < r) { int mid = (l + r) / 2; if ((double)1.0 * (mid * h + (mid - 1) * c) / (2 * mid - 1) > t) l = mid + 1; else r = mid; } if (fabs(t - (double)1.0 * (l * h + (l - 1) * c) / (2 * l - 1)) < fabs(t - (double)1.0 * ((l - 1) * h + (l - 2) * c) / (2 * l - 3))) cout << 2 * l - 1 << endl; else cout << 2 * l - 3 << endl; } int main() { int t = 1; cin >> t; while (t--) { solve(); } }
Educational Codeforces Round 88 (Rated for Div. 2)
原文:https://www.cnblogs.com/likunhong/p/13032042.html