跳到主要内容

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

· 阅读需 1 分钟
lailai
学生 & 开发者

解题思路

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

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

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

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

最终答案为所有记录的交集,即所有 VminV_{\min}最大值VmaxV_{\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;
}