ACM1009:FatMouse' Trade
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%
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#define SIZE 1001
int J[SIZE];
int F[SIZE];
double rate[SIZE];
int bigger(int a, double keyRate, double keyJ);
int main()
{
int M, N;
int i, j, tempIndex;
double tempRate,tempJ,tempF;
double total;
while (scanf("%d%d", &M, &N) == 2)
{
total = 0;
if (M == -1 && N == -1)
break;
for (i = 0; i < N; i++)
{
scanf("%d%d", &J[i], &F[i]);
rate[i] = ((double)F[i] / J[i]);
}
//插入排序
for (i = 1; i < N; i++)
{
tempRate = rate[i];
tempJ = J[i];
tempF = F[i];
tempIndex = i;
j = i - 1;
while (j >= 0 && bigger(j, tempRate, tempJ))
{
rate[j + 1] = rate[j];
J[j + 1] = J[j];
F[j + 1] = F[j];
j = j - 1;
}
rate[j + 1] = tempRate;
J[j + 1] = tempJ;
F[j + 1] = tempF;
} for (i = 0; i < N; i++)
{
//判断比率为0,也就是免费送的情况
if (M > F[i] || rate[i] <= 0.0000001)
{
total += J[i];
M -= F[i];
}
else
{
total += (double)M / F[i] * J[i];
break;
}
}
printf("%0.3f\n", total);
}
} int bigger(int a, double keyRate, double keyJ)
{
if (fabs(rate[a] - keyRate) <= 0.000001)
return J[a] < keyJ;
else
{
return rate[a] > keyRate;
}
}
ACM1009:FatMouse' Trade的更多相关文章
- HDU1009:FatMouse' Trade(初探贪心,wait)
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containi ...
- 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) ...
- 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(简单贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 题目1433:FatMouse (未解决)
题目描述: FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse co ...
- 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) ...
- FatMouse' Trade -HZNU寒假集训
FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...
随机推荐
- docker容器修改hosts文件,重启失效问题解决
docker容器修改hosts文件 搜了一大批资料,有说需要在docker run --hosts...改:dockerfile改:有点麻烦,下面方案比较好: 参照docker吧(https://ti ...
- 沉淀再出发:关于IntelliJ IDEA使用的一些总结
沉淀再出发:关于IntelliJ IDEA使用的一些总结 一.前言 在使用IDEA的时候我们会发现,如果我们先写了一个类的名字,而没有导入这个类的出处,就会提示出错,但是不能自动加入,非常的苦恼,并且 ...
- SQL查询含有%号的字段
select * from EMS_ANNOUNCEMENT where 1=1 and title like '%\%%' escape '\'
- Java 读取Excel数据——POI-3.11 XSSF
POI - the Java API for Microsoft Documents 1.在Apache官网下载Apache最新poi版本:poi-bin-3.11-20141221.zip,解压: ...
- BeanDefinition的创建(BeanDefinitionHolder的创建)
这个对另一篇章Bean Definition从加载.解析.处理.注册到BeanFactory的过程的扩展. Spring框架中BeanDefinition的继承结构. Spring框架中BeanDef ...
- Odoo日历视图
转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9280604.html 一:日历视图定义 根元素为<calendar>. 主要的属性有: co ...
- 7、Spring -Cloud-路由网管Spring Cloud Zuul
7.1.为什么需要Zuul Zuul 作为路由网关组件,在微服务架构中有着非常重要的作用: 7.2.Zuul的工作原理 Zuul 是通过 Servlet 来实现的, Zuul 通过自定义的 Zuu!S ...
- c++ 有swap函数
这是剑指offer数组中重复的数字那个题,直接使用的swap函数 class Solution { public: // Parameters: // numbers: an array of int ...
- shell脚本执行
方法一:切换到shell脚本所在的目录执行shell脚本: cd /data/shell ./hello.sh ./的意思是说在当前的工作目录下执行hello.sh.如果不加上./,bash可能会响应 ...
- 20165302 学习基础和C语言基础调查
学习基础和C语言基础调查 ====== 一,技能学习经验体会 要问我有什么技能比大多数人强,这个我还真的不敢说,虽然我在很多方面都有自己的一些了解,比如乐器和绘画,但也都是一知半解,并没有在某一方面出 ...