FatMouse
时间限制:1 秒
内存限制:128 兆
特殊判题:否
提交:1431
解决:641
- 题目描述:
-
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.
- 输入:
-
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
- 输出:
-
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
- 样例输入:
- 5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
- 样例输出:
- 13.333
31.500#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std; struct goods
{
int J,F;
double xinjia;
}buf[]; bool cmp(goods a,goods b)
{ return a.xinjia<b.xinjia;
} int main()
{
int m,n,j,f;
while(cin>>m)
{
cin>>n;
if(m==-&&n==-) break;
int i;
for(i=;i<n;i++)
{
cin>>j>>f;
buf[i].J=j;
buf[i].F=f;
buf[i].xinjia=(double)f/j;
}
sort(buf,buf+n,cmp); double sum=0.0;
for(i=;i<n;i++)
{
if(buf[i].F<m)
{
sum=sum+buf[i].J;
m=m-buf[i].F;
}
else
{
sum=sum+buf[i].J*(double)m/buf[i].F;
break;
}
} cout<<fixed<<setprecision()<<sum<<endl; }
return ;
} /**************************************************************
Problem: 1433
User: 2009declan
Language: C++
Result: Accepted
Time:10 ms
Memory:1536 kb
****************************************************************/
FatMouse的更多相关文章
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1078 FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- FatMouse' Trade_贪心
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 【HDU 1009】FatMouse' Trade
题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...
- FatMouse的交易问题
想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- CentOS 6.0下面安装JDK7
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html 1. 安 ...
- ARM Linux bootloader笔记
.text //指定了后续编译出来的内容放在代码段[可执行] .global //告诉编译器后续跟的是一个全局可见的名字[可能是变量,也可以是函数名] _start /*函数的其实地址,也是编译.链接 ...
- TensorFlow安装与测试
官网:http://tensorflow.org/安装步骤:1.sudo apt-get install python-pip python-dev python-virtualenv 2.virtu ...
- python django第一天
django第一天,上一次是使用了virtualenv(沙盒),这一次就直接用virtualenv直接建一个django的环境,用来自己练着试试django: source django/Script ...
- [改善Java代码]减少HashMap中元素的数量
在系统开发中我们经常会使用HashMap作为数据集容器,或者是用缓冲池来处理,一般很稳定,但偶尔也会出现内存溢出的问题(OutOfMemory错误),而且这经常是与HashMap有关的.而且这经常是与 ...
- poj 3177 边连通分量
思路: dfs求出所有点的low值,然后对每个连通分量进行缩点,可以通过low来进行缩点.虽然在同一连通分量里可能存在不同的low值,但这并不影响缩点.将每个连通分量缩为一个点后,只要求出这个缩点后的 ...
- mac 如何进入/usr/sbin目录
1.进入terminal, 输入 ls /usr/sbin 2.在finder>前往文件夹,输入路径/usr/sbin
- css3 巧用结构性伪类选择器
最近在国外的一个网站上看到的一个关于结构性伪类选择器的用法,觉得十分实用,就自己尝试了一下,并把它给记录下来: 这是最基本的样式: <style type="text/css" ...
- Android adb常见问题整理(转)
原文地址:http://blog.csdn.net/androiddevelop/article/details/8130416 以下都是ADB连接问题,可以通过尝试如下步骤,由简单度排序 1. 插拔 ...
- winform 上传文件
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...