#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分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论