1009 FatMouse' Trade
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45213 Accepted Submission(s): 15137
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.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct ln{
double x;
double y;
double weight;
}a[];
int cmp(const void*a,const void*b)
{
return (*(struct ln*)a).weight<(*(struct ln*)b).weight?:-;
}
int main()
{
//freopen("in.txt","r",stdin);
int m,n;
while(~scanf("%d%d",&m,&n))
{
memset(a,,sizeof(a));
if(m==-&&n==-)
break;
for(int i=;i<n;i++)
{
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].weight=a[i].x/a[i].y;
}
qsort(a,n,sizeof(struct ln),cmp);
double sum=; for(int i=;i<n;i++)
{
if(m>=a[i].y)
{
sum+=a[i].x;
m-=a[i].y;
}
else
{
sum+=a[i].weight*m;
m=;
}
}
printf("%.3lf\n",sum);
}
return ;
}
1009 FatMouse' Trade的更多相关文章
- HDU 1009 FatMouse' Trade(简单贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- HDOJ.1009 FatMouse' Trade (贪心)
FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- HDU 1009 FatMouse' Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
随机推荐
- 《CDN web加速代理》RHEL6
CDN加速代理环境的测试:192.168.1.这个网段是可以上网的,2网段不可以上网 一台apache服务器 :配置 只安装apche服务 IP 192.168.1.59 一台双网卡的服务器 :只安装 ...
- Entity Framework Code First 常用方法集成
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using S ...
- How to add EDT relation table[AX2012]
setp 1. First create New Edit. setp 2.Create New Table First Table Name is NParentRel then drag and ...
- python学习第七天
一. subprocess 模块 1. subprocess的介绍:用来替代几个老的模块或是函数,如:os.systam,os.popen,os.spawn*,os.popen2*,co ...
- SQL统计——按照各种维度
在SQLserver中可以按照各种维度进行统计,实现与EXCLE一样强大的功能. --========================== --Blog:<奔跑的金鱼> --Desc:&l ...
- ios里的UIActionSheet的使用
class ViewController: UIViewController,UIActionSheetDelegate{ @IBOutlet weak var label1: UILabel! @I ...
- Ubuntu下安装eclipse及PyDev插件注意事项
一.安装eclipse前一定要先安装jdk 1.到http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880 ...
- CentOS6.5安装tomcat7
把下载的apache-tomcat-7.0.19.tar.gz文件上传到服务器的根目录 #tar zxvf apache-tomcat-7.0.19.tar.gz #mv apache-t ...
- 如何阻止iframe里引用的网页自动跳转
今天做了个网页,要在网页http://www.58shuwu.com/to/21766654/Legend%20of%20Miyue/ 里设置一个iframe,然后套用其他的网站.使用http://m ...
- 《Dive into Python》Chapter 2 and Chapter 3 笔记
Example 2.1. odbchelper.py def buildConnectionString(params): """Build a connection s ...