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 ...
随机推荐
- http状态码汇总及问题经验总结
我们经常会遇到404.500.302等提示,它们究竟是什么意思呢?除了这几个常见的状态码外,还有哪些我们没有遇到过的但有可能出现的状态码呢?这里本人做了一个汇总,与大家分享一下. 常见的HTTP错误可 ...
- Mac远程连接服务器
方法一:ssh 方法二:command+K进入远程桌面,这种方式类似于windwos下的远程桌面
- 11、Node.js 函数
内容:普通函数,匿名函数,函数传递是如何让HTTP服务器工作的 ###普通函数例子: function say(word) { console.log(word); } function execut ...
- Debian 9 vsftpd: version 3.0.3 配置
现在网上关于vsftpd的资料不少,但是版本已经比较老,配置起来各种错误,耽误不少时间,现将配置步骤更新如下,配置环境版本:Debian 9 + vsftpd: version 3.0.3 1.apt ...
- Java基础知识强化之集合框架笔记76:ConcurrentHashMap之 ConcurrentHashMap简介
1. ConcurrentHashMap简介: ConcurrentHashMap是一个线程安全的Hash Table,它的主要功能是提供了一组和Hashtable功能相同但是线程安全的方法.Conc ...
- 【[JSOI2007]建筑抢修】
各种瞎写 之后也不知道为什么就过了 刚看到这道题感觉确实是不会的,因为我贪心太差了\(QAQ\) 之后就随便\(yy\)呗 发现首先我们得排一下序,以\(t2\)也就是建筑的损坏时间为第一关键字从小到 ...
- verilog实现的16位CPU设计
verilog实现的16位CPU设计 整体电路图 CPU状态图 idle代表没有工作,exec代表在工作 实验设计思路 五级流水线,增加硬件消耗换取时间的做法. 具体每一部分写什么将由代码部分指明. ...
- 解决java log4j 配置log4jCaused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
前提安装http://mirror.bit.edu.cn/apache/logging/log4j/2.11.2/apache-log4j-2.11.2-bin.zip Buildpath 配置add ...
- 使用navigator.userAgent来进行浏览器嗅探
/*--------------------------------------------------------------------------------* * 功能描述:使用navigat ...
- [Luogu2622]关灯问题$||$(状压$DP$)
#\(\color{red}{\mathcal{Description}}\) \(Link\) 现有\(n\)盏灯,以及\(m\)个按钮.每个按钮可以同时控制这\(n\)盏灯--按下了第i个按钮,对 ...