1 条题解

  • 0
    @ 2025-8-24 22:37:46

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar liangbowen
    不能再摆了,,,

    搬运于2025-08-24 22:37:46,当前版本为作者最后更新于2022-04-24 20:06:50,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    前言

    题目传送门

    $\color{red}{see}\space \color{green}{in}\space \color{blue}{my}\space \color{purple}{blog}$

    这题并不困难,代码也挺短的,题目理解稍有困难。

    题目大意

    (n+1)(n+1) 家商店,也就是 nn 家商店与 NSC 商店。

    求 这 (n+1)(n+1) 家商店 10001000 克香肠的价钱的最小值

    思路

    将所有商店 10001000 克香肠的价钱都求出来,再求最小值即可。

    比如,xxyy 克的香肠,转换成 10001000 克就是 1000×xy\dfrac{1000 \times x}{y} 元。

    代码就很容易写了,注意最后需要保留两位小数。

    完整代码

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
    	int x, y;
    	scanf("%d%d", &x, &y);
    	double ans = 1.0 * x / y * 1000;  //乘上 1.0 强制变成浮点数。 
    	int n;
    	scanf("%d", &n);
    	for (int i = 1; i <= n; i++)
    	{
    		scanf("%d%d", &x, &y);
    		ans = min(ans, 1.0 * x / y * 1000);
    	}
    	printf("%.2lf", ans);  //强制保留两位小数。 
    	return 0;
    }
    
    • 1

    信息

    ID
    7581
    时间
    1000ms
    内存
    32MiB
    难度
    1
    标签
    递交数
    0
    已通过
    0
    上传者