2 条题解

  • 1
    @ 2024-11-23 19:16:32
    #include<iostream>
    #define x first
    #define y second
    using namespace std;
    const int N = 10010;
    typedef pair<int, int> PII;
    PII p[N];
    int n;
    bool check01(int mid)
    {
        for (int i = 1; i <= n; ++ i) if ((p[i].x / mid) > p[i].y) return false;
        return true;
    }
    
    bool check02(int mid)
    {
        for (int i = 1; i <= n; ++ i) if ((p[i].x / mid) < p[i].y) return false;
        return true;
    }
    int main()
    {
        cin >> n;
        for (int i = 1; i <= n; ++ i) scanf("%d%d", &p[i].x, &p[i].y);
    
        int l = 1, r = 1e9;
        while (l < r)
        {
            int mid = (l + r) >> 1;
            if (check01(mid)) r = mid;
            else l = mid + 1;
        }
        cout << r << ' ';
        l = 1, r = 1e9;
        while (l < r)
        {
            int mid = (l + r + 1) >> 1;
            if (check02(mid)) l = mid;
            else r = mid - 1;
        }
        cout << l << endl;
        return 0;
    }
    
    • 0
      @ 2024-11-23 19:17:47

      设答案为 vv, 因为能炼出 bb 个但炼不出 b+1b+1 个所以有 b×vab×v≤aa<(b+1)×va<(b+1)×vab+1<vab\frac{a}{b+1}<v⩽\frac a b

      最小值 ab+1+1\frac{a}{b+1}+1,最大值 ab\frac a b

      #include <iostream>
      #include <cstring>
      #include <algorithm>
      
      using namespace std;
      
      int main()
      {
          int n;
          scanf("%d", &n);
          int minn = 1, maxx = 1e9;
          while (n -- )
          {
              int a, b;
              scanf("%d%d", &a, &b);
              minn = max(minn, a / (b + 1) + 1);
              maxx = min(maxx, a / b);
          }
      
          printf("%d %d\n", minn, maxx);
          return 0;
      }
      
      • 1

      信息

      ID
      5502
      时间
      1000ms
      内存
      256MiB
      难度
      10
      标签
      递交数
      5
      已通过
      2
      上传者