#include <bits/stdc++.h> #define int long long #define debuga(v, i) cout << #v << "[" << i << "]" << " = " << v[i] << '\n'; #define debug(x) cout << #x << " = " << x << '\n'; #define PI 3.1415926 #define INF 0x3f3f3f3f using namespace std; void solve() { int n, a, b; cin >> n; int res_min = -INF; int res_max = INF; for (int i = 1; i <= n; i ++ ) { cin >> a >> b; res_min = max(a / (b + 1), res_min); res_max = min(a / b, res_max); } cout << res_min + 1 << " " << res_max << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T --) { solve(); } return 0; }
#include <bits/stdc++.h> #define int long long #define debuga(v, i) cout << #v << "[" << i << "]" << " = " << v[i] << '\n'; #define debug(x) cout << #x << " = " << x << '\n'; #define PI 3.1415926 #define INF 0x3f3f3f3f using namespace std; vector<pair<int, int>> v; bool check1(int mid) { for (auto t : v) { if (t.first / mid >= t.second + 1) return false; // 说明mid太小了,l = mid + 1; } return true; } bool check2(int mid) { for (auto t : v) { if (t.first / mid <= t.second - 1) return false; // 说明mid太大了, r = mid - 1; } return true; } void solve() { v.reserve(100); int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; v.push_back({a, b}); } int l = 0; int r = 1e9; while (l < r) { int mid = (l + r) >> 1; if (check1(mid)) r = mid; else l = mid + 1; } int res_min = l; // 将left修改为lower_bound,right修改为upper_bound int lower_bound = 0; int upper_bound = 1e9; while (lower_bound < upper_bound) { int mid = (lower_bound + upper_bound + 1) >> 1; if (check2(mid)) lower_bound = mid; else upper_bound = mid - 1; } int res_max = lower_bound; cout << res_min << " " << res_max << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
0.0分
0 人评分