Problem Description
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.
 
Input
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.
 
Output
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.
 
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
 /*
算性价比j[i]/f[i],然后按性价比对每个房间的数据重新排序
再累加最大化兑换比例的老鼠粮
*/
#include <cstdio>
#include <cstdlib>
const int MAX = ;
/*
int compare(const void *a,const void *b)
{
//return *(double*)a - *(double*)b; //小——大
return *(double*)b - *(double*)a; //大——小
}
*/
int main()
{
int m,n,j[MAX]={},f[MAX]={};
while(~scanf("%d%d",&m,&n))
{
if(m==- && n==-)
break;
double j_f[MAX]={},temp=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&j[i],&f[i]);
j_f[i]=(double)j[i]/f[i];
}
//快速排序:数组首地址,元素个数,一个元素大小,指向比较函数的指针
//qsort(j_f+1,n,sizeof(double),compare);
//好吧,写到一半发现排序不能这样用- -排序函数还是留着吧- -
for(int i=;i<=n-;i++)
{
for(int k=i+;k<=n;k++)
{
if(j_f[i]<j_f[k])
{
temp=j_f[k];
j_f[k]=j_f[i];
j_f[i]=temp; temp=j[k];
j[k]=j[i];
j[i]=(int)temp; temp=f[k];
f[k]=f[i];
f[i]=(int)temp;
}
}
}
double ans=;
for(int i=;i<=n;i++)
{
if(m>=f[i])
{
ans+=j[i];
m-=f[i];
}
else
{
ans+=m*j_f[i];
break;
}
}
printf("%.3lf\n",ans);
}
return ;
}

HDU_1009——老鼠的交易,性价比排序,最大化收益的更多相关文章

  1. HDU 1009 FatMouse' Trade肥老鼠的交易(AC代码) 贪心法

    题意: 一只老鼠用猫粮来换豆子,每个房间的兑换率不同,所以得尽量从兑换率高的房间先兑换.肥老鼠准备M磅猫粮去跟猫交易,让猫在warehouse中帮他指路,以找到好吃的.warehouse有N个房间,第 ...

  2. HDU——1009FatMouse' Trade(贪心+结构体+排序)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. Contest Hunter Round #70 - 连续两大交易事件杯省选模拟赛

    orz lydrainbowcat [Problem A]「艦これ市」70万幕后交易事件 排序机器=-=.重要的是相同的处理. 我们可以从小到大添加数字,然后维护一个位置的序列.每一种相等的数字都在一 ...

  4. [转] 深度探索Hyperledger技术与应用之超级账本的典型交易流程

    转自: https://blog.csdn.net/HiBlock/article/details/80212499 个人感觉对交易流程描述的比较清楚,转载以备查看. 1 典型交易流程 下图所示为Hy ...

  5. Fabric交易流程

    (内容可能有些乱,请见谅,日后会对格式进行整理!) #### 在1.0及以后的版本中,客户端应用会先向Fabric CA申请用户所需要的Fabric中的准入证书,用于签名提案以及交易,然后由客户端(A ...

  6. Hyperledger Fabric(2)共识与交易

    Fabric 的网络节点本质上是互相复制的状态机,节点之间需要保持相同的账本状态.为了实现这个目的,各个节点需要通过共识( consensus )过程,对账本状态的变化达成一致性的认同. Fabric ...

  7. 区块链Fabric 交易流程

    1. 提交交易预案 1)应用端首先构建交易的预案,预案的作用是调用通道中的链码来读取或者写入账本的数据.应用端使用 Fabric 的 SDK 打包交易预案,并使用用户的私钥对预案进行签名. 应用打包完 ...

  8. A cost-effective recommender system for taxi drivers

    一个针对出租车司机有效花费的推荐系统 摘要 GPS技术和新形式的城市地理学改变了手机服务的形式.比如说,丰富的出租车GPS轨迹使得出做租车领域有新方法.事实上,最近很多工作是在使用出租车GPS轨迹数据 ...

  9. 基于Multiple treatment的营销评估算法

    营销是发现或挖掘准消费者和众多商家需求,通过对自身商品和服务的优化和定制,进而推广.传播和销售产品,实现最大化利益的过程.例如,银行可通过免息卡或降价对处在分期意愿边缘的用户进行营销,促使其分期进而提 ...

随机推荐

  1. 使用solr报错,错误信息 include(SolrClient.php): failed to open stream: No such file or directory

    这个是因为本地没有安装php-solr的扩展导致的,安装方法(使用的是ubuntu) cd /optwget http://pecl.php.net/get/solr-1.0.2.tgztar -xv ...

  2. Linux用户磁盘配额

    一:内核中支持QUOTA: [root@localhost /]# grep  CONFIG_QUOTA /boot/config-3.10.0-123.el7.x86_64 CONFIG_QUOTA ...

  3. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  4. 【网络流#6】POJ 3041 Asteroids 二分图最大匹配 - 《挑战程序设计竞赛》例题

    学习网络流中ing...作为初学者练习是不可少的~~~构图方法因为书上很详细了,所以就简单说一说 把光束作为图的顶点,小行星当做连接顶点的边,建图,由于 最小顶点覆盖 等于 二分图最大匹配 ,因此求二 ...

  5. 菜鸟学习Ado.net笔记一:Ado.net学习之SqlHelper类

    using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...

  6. 母函数&&排列(模板)

    #include <iostream> #include <algorithm> using namespace std; int main() { int n,i; int ...

  7. Android Translate 动画跳跃和缓慢移动

    1.动画跳跃:在动画结束的时候设置位置 Animation.AnimationListener listener = new Animation.AnimationListener() { @Over ...

  8. String在JAVA里是固定长度的吗?为什么可用“+”连接

    所谓长度固定不是你理解的意思而是说String类中存储的char[]是final的,不能修改,你对String的操作实际上是产生了一个新的String,对于某一个String来说,长度就是固定的了 S ...

  9. Starting nagios:This account is currently not available nagios

    nagios在启动时报错 # service nagios restartRunning configuration check…done.Stopping nagios: done.Starting ...

  10. JavaScript 客户端JavaScript之 脚本化文档

    客户端JavaScript的存在把静态HTML转变为交互式的Web应用程序,脚本化Web页面的内容正是JavaScript存在的理由.   一个文档对象模型或者说DOM就是一个API,它定义了如何访问 ...