题解:P9240 [蓝桥杯 2023 省 B] 冶炼金属

· · 题解

解题思路

b 变成 b+1,即再造一个特殊金属 X 时,V=\left\lfloor\frac{a}{b+1}\right\rfloor。此时为 恰好不满足条件的情况,因此 满足条件的最小情况 为:

V_{\min}=\left\lfloor\frac{a}{b+1}\right\rfloor+1

同理,满足条件的最大情况 为:

V_{\max}=\left\lfloor\frac{a}{b}\right\rfloor

最终答案为所有记录的交集,即所有 V_{\min}最大值V_{\max}最小值

参考代码

#include <bits/stdc++.h>
using namespace std;

const int inf=0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    int mn=0,mx=inf;
    while(n--)
    {
        int a,b;
        cin>>a>>b;
        mn=max(mn,a/(b+1)+1);
        mx=min(mx,a/b);
    }
    cout<<mn<<' '<<mx<<'\n';
    return 0;
}