洛谷 P8295 题解

题目传送门


题意:

给定一个标准价格和 \(n\),然后给出 \(n\) 个不同的价格,找出最便宜的买 \(1000\) 克香肠的价格。


思路:

模拟题,直接根据题意进行模拟即可。

可以进行比较每家店每克的价格,最后在乘 \(1000\) 即可。


code:

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

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}

int x,y,n;
double ans;

int main(){
	x=read();y=read();n=read();
	ans=1.0*x/y;
	for(int i=1;i<=n;i++){
		x=read();y=read();
		ans=min(ans,1.0*x/y);
	}
	printf("%.2lf",ans*1000);
	return 0;
}


posted @ 2022-05-06 18:40  Black--Panda  阅读(37)  评论(0编辑  收藏  举报