#include "iostream"
#include "algorithm"
#include "cstdio"
using namespace std; struct Point
{
int x;
int y;
double z;
}; bool cmp(const Point &a,const Point &b)
{
return a.z > b.z;
}
int main()
{
while()
{
int M;
int n; cin >> M >> n; if(M == - && n == -)
break;
Point *point = new Point[n];
for(int i=;i<n;i++) //sort
{
cin >> point[i].x >> point[i].y ;
point[i].z = double(point[i].x)/double(point[i].y);
}
sort(point,point+n,cmp); double food = ;
int i;
for(i=;i<n;i++) //caculate
{
if(M >= point[i].y)
{
M = M - point[i].y;
food = food + point[i].x;
} else
{
food = food + double(M) * point[i].x/point[i].y; //当double与整数相乘(除)就会变成double,完美的解决了精度的问题。遇到精度问题时,一定要把高精度数放在前面。
break;
} }
printf("%.3lf\n",food); }
return ;
}

第一:精度问题,要将高精度的放在表达式前面进行优先处理。

第二:反复记忆上述的指针排序法

1.用指针new空间

2.函数传入的指针写法

3.在结构体内部的东西可以用这种方法排序,比较灵活,可以随意的在结构体内部增加或删减元素

HDOJ1009的更多相关文章

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

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

  2. HDOJ-1009 FatMouse' Trade

    http://acm.hdu.edu.cn/showproblem.php?pid=1009 # include <stdio.h> # include <algorithm> ...

  3. FatMouse' Trade(hdoj1009)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  4. HDOJ----------1009

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

随机推荐

  1. C/C++之面向对象

    面向对象的三个基本特征(讲解) 面向对象的三个基本特征是:封装.继承.多态. 封装 封装最好理解了.封装是面向对象的特征之一,是对象和类概念的主要特性. 封装,也就是把客观事物封装成抽象的类,并且类可 ...

  2. ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_00163'

    早上一运维同事说,一个报盘程序启动的时候报了"ESOURCE_LOCKED - cannot obtain exclusive access to locked queue '2484_0_ ...

  3. C++面向对象高级开发课程(第二周)

    1. 类中含有指针—— class with pointer member(s) ——的情况经常发生,典型的有:string 类. 2. STL中的 string 类太复杂,copy on write ...

  4. 01: JavaScript实例

    1.1 基础 JavaScript 实例 <body> <script type="text/javascript"> document.write(&qu ...

  5. Windows中的时间(SYSTEMTIME和FILETIME) (转载)

    转载:http://blog.csdn.net/bokee/article/details/5330791 两种时间系统之间没有本质区别(事实上CRT时间是用Windows时间实现的,当然这是说的VC ...

  6. Python3基础 sys.path.append 增加模块的搜索路径

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. 获取mips32机器的各数据类型的取值范围

    一.背景: 使用的mips 32bit机器,32bit的vxworks操作系统(各机器带来的范围都不一样,与操作系统也有关联) 二.验证类型的范围: 2.1 unsigned long: void m ...

  8. MariaDB学习记录

    MariaDB的学习 MariaDB的学习 关于MariaDB的历史,不再概述 下面是mariadb的官网:https://mariadb.com/ 同样的,MariaDB一样有连接java的jar包 ...

  9. IEnumerable与IEnumerator

    IEnumerable接口 IEnumerable接口:实现该接口的类,表明该类下有可以枚举的元素 public interface IEnumerable { //返回一个实现了IEnumerato ...

  10. hdu 2874 Connections between cities 带权lca判是否联通

    Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...