A - FatMouse' Trade
Description
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.
Input
is followed by two -1's. All integers are not greater than 1000.
Output
Sample Input
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
13.333
31.500
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct p
{
double a;
double b;
double c;
};
bool compare(p A,p B)
{
return A.c>B.c;
}
int main()
{
int m,n,i,j;
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==-1&&n==-1)
break;
p t[1001];
for(i=0;i<n;i++)
{
cin>>t[i].a>>t[i].b;
t[i].c=t[i].a/t[i].b;
}
sort(t,t+n,compare);
double count=0;
for(i=0;i<n;i++)
{
count+=t[i].b;
if(count>m)
break;
}
double sum=0;
//if(i==0)
//printf("%.3lf\n",t[0].c*m);
if(count<m)
{
for(j=0;j<n;j++)
sum+=t[j].a;
printf("%.3lf\n",sum);
}
else
{
for(j=0;j<i;j++)
{
sum+=t[j].a;
m-=t[j].b;
}
printf("%.3lf\n",sum+m*t[i].c);
}
}
return 0;
}
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int m,n;
int i,j;
double a[1002],b[1002];
double c[1002];
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==-1&&n==-1)
break;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
c[i]=a[i]/b[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(c[j+1]>c[j])
{
swap(b[j],b[j+1]);
swap(a[j],a[j+1]);
swap(c[j],c[j+1]);
}
}
}
double count=0;
for(i=0;i<n;i++)
{
count+=b[i];
if(count>m)
break;
}
double sum=0;
if(count<m)
{
for(j=0;j<n;j++)
sum+=a[j];
printf("%.3lf\n",sum);
}
else
{
for(j=0;j<i;j++)
{
sum+=a[j];
m-=b[j];
}
printf("%.3lf\n",sum+m*c[i]);
}
}
return 0;
}
A - FatMouse' Trade的更多相关文章
- 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) ...
- 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- FatMouse' Trade
/* problem: FatMouse' Trade this is greedy problem. firstly:we should calculate the average J[i]/F[i ...
- HDU1009 FatMouse' Trade
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 ...
- FatMouse' Trade -HZNU寒假集训
FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...
- FatMouse' Trade(杭电ACM---1009)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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 ...
随机推荐
- send js object to webapi or mvc
[HttpPost] public HttpResponseMessage AddInfo(UserInfoEntity userInfo) { return Request.CreateRespon ...
- android的Log日志打印管理工具类(一)
android的Log日志的打印管理工具类: package com.gzcivil.utils; import android.util.Log; /** * 日志打印管理 * * @author ...
- EBS R12 怎么修改APPS密码
apps 和 applsys 的口令 $> FNDCPASS apps/<apps password> 0 Y system/<system password> SYST ...
- MySQL:ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
MySQL在删除一张表时出现 ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fa ...
- JVM学习之实例分析JVM安全体系
转自:http://www.importnew.com/17093.html,感谢分享 类加载器的作用就是将真实的class文件根据位置将该Java类的字节码装入内存,并生成对应的Class对象.用户 ...
- QF——UI之UIImageView及UIView的形变属性transform
UIImageView: 专门用来放置图片的视图.它里面放置的图片是[UIImage imageNamed: (NSString) imgName]生成的,注意千万别只写成图片NSString类型的名 ...
- QF——OC的多态,动态绑定及实现原理
多态: 封装,继承,多态是面向对象的三大特征. 那多态到底是什么呢? 多态:允许不同的类定义相同的方法,OC能自己判断当前类所对应的方法,不会混乱. 动态类型:程序直到运行时才确定对象的类型. 动态绑 ...
- 安装虚拟机VMWare时出现1021错误的解决办法
今天安装虚拟机(VMWare Workstation9.0),中途老是出现错误:Failed to create the requested registry key key installer er ...
- CSS 技术关键字
CSS 技术关键字 元素 替换元素 非替换元素------替换元素和非替换元素的分类是CSS范畴内的,其它的分类都不属于CSS定义的 替换元素和非替换元素的定义是出于“我 ...
- 强制删除正在连接的Oracle用户,以删除SDE用户为例
. 有时候想强制删除一个已经连接的Oracle用户,不能直接删除,可以用Kill会话信息. 比如今天想删除一个被连接的SDE用户,可以用以下方法删除一个“正在被连接”的用户. 1.查看所有用户的会话信 ...