FatMouse' Trade(杭电1009)

FatMouse' Trade(杭电1009)

大家好,又见面了,我是全栈君。

FatMouse’ Trade

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1

Font: Times New Roman | Verdana | Georgia

Font Size:  

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
//本题是简单贪心问题。意思是老鼠有m榜猫粮,通过给猫粮东西data[i].b能够兑换data[i].a,求最多能够兑换多少食物。

//仅仅需将data[i].a/data[i].b的值从大到小排序就可以求解。

#include<stdio.h>struct st{ double a; double b; double c;}data[1000];int main(){ int i,j,m,n; struct st data[1000],t; while(scanf("%d %d",&m,&n)&&(m!=-1||n!=-1)) { double sum=0.000; for(i=0;i<n;i++) { scanf("%lf %lf",&data[i].a,&data[i].b); } for(i=0;i<n;i++) { for( j=i+1;j<n;j++) { if((data[i].a/data[i].b)<data[j].a/data[j].b) { t=data[i]; data[i]=data[j]; data[j]=t;} } } for(i=0;i<n;i++) { if(m-data[i].b>=0.001) { sum+=data[i].a; m-=data[i].b; } else { sum=sum+m*data[i].a/data[i].b; break; } } printf("%.3lf\n",sum); } return 0;}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116298.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 二叉树性质[通俗易懂]

    二叉树性质[通俗易懂]转载skywang12345 http://www.cnblogs.com/skywang12345/p/3576328.html树的介绍1.树的定义树是一种数据结构,它是由n(n>=1)个有限节点组成一个具有层次关系的集合。把它叫做“树”是因为它看起来像一棵倒挂的树,也就是说它是根朝上,而叶朝下的。它具有以下的特点:(01)每个节点有零个或多个子

    2022年5月31日
    34
  • Altium Designer 入门教程

    Altium Designer 入门教程注:使用了引用语法但不是引用:以下内容有部分来源于网络、博客等等,结尾会给出参考链接。(๑•ั็ω•็ั๑)希望大家可以自觉的在转载、转发时著名出处。(๑•.•๑)预防侵权,支持原创,支持开源,从你我做起。= ̄ω ̄=放在开始如果您喜欢我的文章,拜托点赞+收藏+关注,博主会根据大家喜好来推出相关系列文章~更多精彩内容也可以访问我的博客Aelous-BLog/***Copyright(C),2019-2020,xudongpo.cn*Author:许东坡*Email.

    2022年7月13日
    22
  • petalinux-package_centos7安装详细图解

    petalinux-package_centos7安装详细图解PetalLinux是Xilinx公司推出的嵌入式Linux开发工具,专门针对Xilinx公司的FPGASoC芯片和开发板,用户可以在PetaLinux工具的帮助下进行完整的开发流程,包括设计,验证,仿真,下载等。本文将详细介绍PetaLinux的安装流程,虽然实际上基本就是把Xilinx的UG1144翻译一遍。

    2022年9月11日
    0
  • eplan激活码破解步骤win10【2021.7最新】

    (eplan激活码破解步骤win10)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~MLZP…

    2022年3月21日
    1.4K
  • 视频直播解决方案

    视频直播解决方案背景当下,视频直播行业在中国逐渐走红。在刚刚过去的2015年,视频直播成为互联网行业最抢眼的领域之一。从游戏到秀场,从传统的网页端到移动互联网,各大直播平台包括斗鱼、熊猫tv、虎牙战旗还有纯移动端的印客、易直播等,群雄割据。言归正转,毕竟本文是一篇技术博客,接下来让我们从技术的角度分析如何搭建一个自己的直播平台。流程图首先让我们看一下直播整体流程。首先是直播视频采集端,

    2022年7月24日
    7
  • Dynamips模拟3660桥接PC后与实际网络通讯问题

    Dynamips模拟3660桥接PC后与实际网络通讯问题

    2021年7月26日
    74

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号