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 ...
随机推荐
- Android(java)学习笔记104:Map集合的遍历之键找值
package cn.itcast_01; import java.util.HashMap; import java.util.Map; import java.util.Set; /* * Map ...
- web2.0、互联网+、IT时代与DT时代、工业4.0 引发的思考
最近忙着找实习,来学校一个星期还没到,就感觉已经经历了几个春秋. 第一个实习面试是个杭州互联网小公司,面WEB前端开发实习,怪我一个暑假两个月一点书都没碰,偏偏赶上G20到9/9才开学,没啥准备就一头 ...
- python解决SNIMissingWarning和InsecurePlatformWarning警告
在想要获取https站点的资源时,会报出SNIMissingWarning和InsecurePlatformWarning警告 SNIMissingWarning: An HTTPS request ...
- 使用Xpath从网页中获取数据
/// <summary> /// 从官方网站中抓取产品信息存放在本地数据库中 /// </summary> /// <returns></returns&g ...
- PetShop
Microsoft .NET Pet Shop 4:将 ASP.NET 1.1 应用程序迁移到 2.0 发布日期: 2006-5-9 | 更新日期: 2006-5-9 适用于:Microsoft .N ...
- C# winform 选择项 省市连动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 学习之spring自带缓存
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://w ...
- PHP的语言规范
PHP的语言规范: 1.php中的变量名区分大小写,但是函数名,类名,方法名,不区分大小写,但建议区分大小写 2.php代码必须书写在<?php?>(php标签),开启标记(<?ph ...
- Bootstrap学习笔记(三) 网格系统
4-1实现原理 网格系统的实现原理非常简单,仅仅是通过定义容器大小,平分12份(也有平分成24份或32份,但12份是最常见的),再调整内外边距,最后结合媒体查询,就制作出了强大的响应式网格系统.Boo ...
- Libcurl笔记五_easy模式运行原理
1, curl_easy_init内部调用Curl_open创建一个结构体SessionHandle(里面包含了所以curl使用的数据和指针)并初始化一些数据,然后返回将其作为给外侧使用的句柄CURL ...