P9240 [蓝桥杯 2023 省 B] 冶炼金属(比值问题)

数学分析:

1. max(最大比值) = A/B 余数p(p<B)

=> A=max*B+p

反证:若max不为最大,则设max+n为最大比值

(max+n)*B=max*B+n*B+p1 > A (n*B+p1 > p ,矛盾)

故max为最大比值

2.min(最小比值) = (A/(B+1))+ 1

分析:

(A/(B+1))是对于B+1的最大比值,加一即为对于B的最小比值

问题分析:

对于每组数据计算最大,最小比值

输出全部数据中

最小的最大比值 与 最大的最小比值

AC代码:

复制代码
#include<iostream>
using namespace std;

int main()
{
	int num; cin >> num;
	int max = -1,min=1000000009;
	for (int i = 0; i < num; i++)
	{
		int n = 0, target = 0;
		scanf("%d %d", &n, &target);
		if (min > n / target) min = n / target;
		if (max < (n / (target + 1)) + 1) max = (n / (target + 1)) + 1;
	}cout <<max <<" " << min << endl;


		return 0;
}
相关推荐
geats人山人海6 小时前
算法基础第六讲 图论
算法·深度优先·图论
风落青芜8 小时前
排序算法(四):归并排序、计数排序与算法总结
c语言·开发语言·数据结构·算法·排序算法
@陈小鱼9 小时前
基于InceptionTime网络的PPG无创血压估计算法研究
人工智能·python·算法·回归·开源·ppg·血压估计
liulilittle15 小时前
认识麻将 —— 流水及对账
算法·游戏·lua·对账·流水·资金·玩法
郝学胜-神的一滴19 小时前
Effective Python 条款44:善用属性注解
开发语言·c++·vscode·python·算法·stl
青少儿编程课堂1 天前
第十八届蓝桥杯青少组图形化真题:校园分形雪花绘制解析(全国青少年信息素养大赛·电子学会图形化考级冲刺)
c++·python·算法·bfs·信息学竞赛
geovindu2 天前
python: KNeighborsClassifier K
开发语言·后端·python·算法
让我们一起加油好吗2 天前
【数据结构】线段树详解
数据结构·c++·算法·线段树·洛谷