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

Author

CHEN, Yue

Source

ZJCPC2004

#include<stdio.h>
#include<algorithm>//sort的头文件
using namespace std;
const int maxn=+;
struct node{
double j,f;
double r;
}a[maxn];
bool cmp(node a,node b)//从大到小排序
{
return a.r>b.r;
}
int main()
{
int m,n,i;
double sum;
while(scanf("%d%d",&m,&n)==&&(m!=-&&n!=-))
{
for(i=;i<n;i++){
scanf("%lf%lf",&a[i].j,&a[i].f);
a[i].r=a[i].j/a[i].f;
}
sort(a,a+n,cmp);
sum=0.0;
for(i=;i<n;i++)
{
if(m>=a[i].f)
{
sum+=a[i].j;
m-=a[i].f;
}
else
{
sum+=(a[i].r)*m;
break;
}
}
printf("%.3lf\n",sum);
}
return ;
}

HDU1009FatMouse' Trade(贪心)的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

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

  2. HDU 1009 FatMouse' Trade(贪心)

    FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...

  3. HDOJ.1009 FatMouse' Trade (贪心)

    FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...

  4. hdoj1009 FatMouse' Trade——贪心算法

    贪心思路:按单位猫粮能兑换到的javaBean从大到小将组合进行排序,总是在当前兑换尽可能多的javabeans 问题描述:点击打开链接 hdoj1009 FatMouse's Trade 源代码: ...

  5. ZOJ FatMouse' Trade 贪心

    得之我幸,不得,我命.仅此而已. 学姐说呀,希望下次看到你的时候依然潇洒如故.(笑~) 我就是这么潇洒~哈哈. 感觉大家比我还紧张~ 我很好的.真的 ------------------------- ...

  6. FatMouse' Trade (贪心)

    #include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...

  7. SGU 280.Trade centers(贪心)

    SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...

  8. HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...

  9. 20181009noip HZ EZ 两校联考trade(优先队列,贪心)

    题面戳这里 思路: 裸的,贪心... 考场上写了一个数据分治(70ptsDP,30pts线段树优化贪心,GG了后30分) 这道题其实很简单的 我们看图: 我们在A时刻买一个东西,在B时刻卖出去,我们可 ...

随机推荐

  1. SR-IOV简介

    转载:http://docs.oracle.com/cd/E38902_01/html/E38873/glbzi.html SR-IOV 技术是一种基于硬件的虚拟化解决方案,可提高性能和可伸缩性.SR ...

  2. [HMLY]8.Cocoa

    cocoa是苹果公司为mac os x所创建的原声面向对象API,是mac os x上五大API之一,其他四个是carbon,posiX,x11,java. 苹果的面向对象开发框架,用来生成 Mac ...

  3. git 本地给远程仓库创建分支 三步法

    命令如下: 1:本地创建分支dev Peg@PEG-PC /D/home/myself/Symfony (master) $ git branch dev 2:下面是把本地分支提交到远程仓库 Peg@ ...

  4. C# 匿名方法和拉姆达表达式

    有时候,我们需要封装一组数据,只有数据,没有方法,并且只用于当前程序,不需要在项目间重用,这时候,如果是传统的使用类来封装的话,大概会是下面这种样子: internal class SomeData ...

  5. Ubuntu 16.04 samba相关配置

    samba是 SMB/CIFS网络协议的重新实现,它作为NFS的补充使得在Linux和Windows系统之间进行文件共享.打印更容易实现. 相关介绍: SAMBA套件: (1)samba:这个套件主要 ...

  6. 采用Jenkins搭建持续集成环境

    Jenkins介绍 Jenkins是一个CI工具.它可以根据设定持续定期编译,运行相应代码:运行UT或集成测试:将运行结果发送至邮件,或展示成报告... 这样做的最终目的是: 让项目保持健康的状态.如 ...

  7. Ansible Filter

    没啥好说的. 自己看吧 http://docs.ansible.com/ansible/playbooks_filters.html

  8. AC日记——【模板】字符串哈希 洛谷 3370

    题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. 友情提醒:如果真的想好好练习哈希的话,请自觉,否则请右转 ...

  9. CentOS7中将Mysql添加为系统服务

    如果是自己通过tar包安装的Mysql,不会自动添加到系统服务中,可通过如下方式,自己添加. 先启动一下mysql ${mysql}/support-files/mysql.server start ...

  10. 洛谷-均分纸牌-NOIP2002提高组复赛

    题目描述 Description 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸 ...