Codeforces Round #460 (Div. 2)-A Supermaket(贪心)
2 seconds
256 megabytes
standard input
standard output
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that a yuan for b kilos
(You don't need to care about what "yuan" is), the same as a / b yuan for
a kilo.
Now imagine you'd like to buy m kilos of apples. You've asked n supermarkets
and got the prices. Find the minimum cost for those apples.
You can assume that there are enough apples in all supermarkets.
The first line contains two positive integers n and m (1 ≤ n ≤ 5 000, 1 ≤ m ≤ 100),
denoting that there are n supermarkets and you want to buy m kilos
of apples.
The following n lines describe the information of the supermarkets. Each line contains two positive integers a, b (1 ≤ a, b ≤ 100),
denoting that in this supermarket, you are supposed to pay a yuan for b kilos
of apples.
The only line, denoting the minimum cost for m kilos of apples. Please make sure that the absolute or relative error between your answer
and the correct answer won't exceed 10 - 6.
Formally, let your answer be x, and the jury's answer be y.
Your answer is considered correct if
.
3 5
1 2
3 4
1 3
1.66666667
2 1
99 100
98 99
0.98989899
In the first sample, you are supposed to buy 5 kilos of apples in supermarket 3.
The cost is 5 / 3 yuan.
In the second sample, you are supposed to buy 1 kilo of apples in supermarket 2.
The cost is 98 / 99 yuan.
贪心,做商排序即可。
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 10005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
#define maxn 5005
struct Pay
{
double w;
double v;
double pri;
} s[maxn];
int cmp(Pay a, Pay b)
{
return a.pri < b.pri;
}
int main()
{
int m, i, n;
Pay s[maxn];
read(m), read(n);
for (i = 0; i < m; i++)
{
scanf("%lf%lf", &s[i].v, &s[i].w);
s[i].pri = s[i].v / s[i].w;
}
sort(s, s + m, cmp);
printf("%.10f", n * s[0].pri);
return 0;
}
Codeforces Round #460 (Div. 2)-A Supermaket(贪心)的更多相关文章
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
随机推荐
- http之抽丝剥茧,深度剖析http的那些事儿
最近,小编一心扎跟学技术,毫不顾及头发的掉落速度,都快成地中海了,不过也无大碍,谁让咱是一个爱钻技术的男人呢.最近两周老是看到http,那么这个http,有哪些猫腻呢,很多同学都有这种理解,就是对于h ...
- flask-url_for
flask-url_for flask的url_for函数和django的reverse函数类似,都是提供视图反转url的方法 from flask import Flask, url_for app ...
- webpack配置示例
var webpack = require('webpack'); var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('commo ...
- Linux基础管理篇,软件管理程序,yum与rpm
一.RPM 一般来说,rpm类型的文件在安装的时候,会检测当前的系统是否满足当前软件需要的环境.若符合,则该软件就会被安装,并且会把软件的相关信息写入/var/lib/rpm/目录下的数据库文件中. ...
- Vue项目添加动态浏览器头部title
0. 直接上 预览链接 + 效果图 Vue项目添加动态浏览器头部title 1. 实现思路 ( 1 ) 从路由router里面得到组件的title ( 2 ) title存vuex (本项目已经封装h ...
- Array(数组)对象-->sort() 方法
1.定义和用法 sort() 方法用于对数组的元素进行排序. 默认排序顺序为按字母升序. 语法: array.sort(sortfunction) 参数: sortfunction:规定排序顺序.必须 ...
- 127.0.0.1和localhost区别
- 数据结构和算法(Golang实现)(14)常见数据结构-栈和队列
栈和队列 一.栈 Stack 和队列 Queue 我们日常生活中,都需要将物品排列,或者安排事情的先后顺序.更通俗地讲,我们买东西时,人太多的情况下,我们要排队,排队也有先后顺序,有些人早了点来,排完 ...
- Pytorch自定义创建BP神经网络
class BPNet(nn.Module): def __init__(self, in_dim, n_hidden_1, n_hidden_2,\ n_hidden_3, n_hidden_4, ...
- 【Tool】IDEA配置Maven依赖管理
IDEA配置Maven 打开IDEA,在项目界面打开[File] — [Settings] 找到构建工具,下面第一个就是Maven 主选项更换我们自己的主目录和设置目录与本地仓库 勾选[打印异常捕获信 ...