/*
problem: FatMouse' Trade
this is greedy problem.
firstly:we should calculate the average J[i]/F[i] and sort it
secondly: according to the m and choose the most high ones
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std; struct cell
{
double j;
double f;
double rate;
};
bool cmp(cell x,cell y)
{
return x.rate > y.rate;
}
int main()
{
int m,n;
cell temp;
vector<cell> vec;
while (scanf("%d%d", &m, &n) != EOF)
{
if ((m == -1)&&(n == -1))
break;
double count = 0.0;
while (n--)
{
cin>>temp.j>>temp.f;
if (temp.f != 0)
{
temp.rate = (double)temp.j/temp.f;
vec.push_back(temp);
}
else
{
count += temp.j;
} }
sort(vec.begin(), vec.end(), cmp);
for (int i = 0; (i < vec.size())&&(m > 0); i++)
{
if (m-vec[i].f >= 0)
{
count += vec[i].j;
m -= vec[i].f;
}
else
{
//count += (double)((double)(m/vec[i].f))*vec[i].j;
double temp1 = (double)m/vec[i].f;
count += temp1*vec[i].j;
m = 0;
}
}
vec.clear();
printf("%.3f\n",count);
}
}
/*此题除了要满足例子以外,还要满足一些条件才能真正算ac:
0 1
1 0
1.000 1 0
0.000 5 4
10000 5
2000 2
100 0
300 0
10400.000 数据类型用double,就这样*/

FatMouse' Trade的更多相关文章

  1. Hdu 1009 FatMouse' Trade

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

  2. hdu 1009:FatMouse' Trade(贪心)

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

  3. 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) ...

  4. 1009 FatMouse' Trade

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

  5. HDU1009 FatMouse' Trade

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

  6. HDU 1009 FatMouse' Trade(贪心)

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

  7. FatMouse' Trade -HZNU寒假集训

    FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...

  8. FatMouse' Trade(杭电ACM---1009)

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

  9. 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 ...

随机推荐

  1. div模拟的下拉框特效jquery

    从网上找来的,感觉不错就拿来分享下 <style type="text/css"> body, ul, li { margin: 0; padding: 0; font ...

  2. IE 8兼容:X-UA-Compatible的解释

    来源:http://www.ido321.com/940.html 来自StackOverFlow 问题描述: 1: <meta http-equiv="X-UA-Compatible ...

  3. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

  4. mybatis系列-13-resultMap总结

    resultType: 作用: 将查询结果按照sql列名pojo属性名一致性映射到pojo中. 场合: 常见一些明细记录的展示,比如用户购买商品明细,将关联查询信息全部展示在页面时,此时可直接使用re ...

  5. ini_set /ini_get函数功能-----PHP

    配置PHP环境时,我们记得最初的一步就是修改php.ini文件,但是当我们在虚拟机中运行脚本,或者是我们因为其他的原因没有修改php.ini的权限时,我们该怎么办? ini_set()函数提供了在脚本 ...

  6. Hadoop-Map/Reduce实现实现倒排索引

    先来简单介绍一下什么是文档倒排索引 倒排索引是文档检索系统中最常见的数据结构,被广泛应用在全文搜索引擎上.主要用来存储某个单词(或词组)在一个文档或者一组文档中的存储位置的映射,即提供了一种根据内容来 ...

  7. Java 从单核到多核的多线程(并发)

    JAVA 并发编程       最初计算机是单任务的,然后发展到多任务,接着出现多线程并行,同时计算机也从单cpu进入到多cpu.如下图: 多任务:其实就是利用操作系统时间片轮转使用的原理.操作系统通 ...

  8. Tengine – Nginx衍生版

    Tengine是淘宝在Nginx基础上开发的一个衍生版.官方的简介说针对大访问量网站的需求,添加了很多高级功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验. ...

  9. struts2+Hibernate4+spring3+EasyUI环境搭建之五:引入jquery easyui

    1.下载jquery easyui组件     http://www.jeasyui.com/download/index.php 2.解压 放到工程中  如图 3.jsp引入组件:必须按照如下顺序 ...

  10. Gym 100818I Olympic Parade(位运算)

    Olympic Parade http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/I [题意]: 给出N个数,找出 ...