HDU1009FatMouse' Trade(贪心)
Problem Description
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
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
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
Source
#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(贪心)的更多相关文章
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- HDOJ.1009 FatMouse' Trade (贪心)
FatMouse' Trade 点我挑战题目 题意分析 每组数据,给出有的猫粮m与房间数n,接着有n行,分别是这个房间存放的食物和所需要的猫粮.求这组数据能保证的最大的食物是多少? (可以不完全保证这 ...
- hdoj1009 FatMouse' Trade——贪心算法
贪心思路:按单位猫粮能兑换到的javaBean从大到小将组合进行排序,总是在当前兑换尽可能多的javabeans 问题描述:点击打开链接 hdoj1009 FatMouse's Trade 源代码: ...
- ZOJ FatMouse' Trade 贪心
得之我幸,不得,我命.仅此而已. 学姐说呀,希望下次看到你的时候依然潇洒如故.(笑~) 我就是这么潇洒~哈哈. 感觉大家比我还紧张~ 我很好的.真的 ------------------------- ...
- FatMouse' Trade (贪心)
#include <iostream> #include <stdio.h> #include <cstring> #include <cmath> # ...
- SGU 280.Trade centers(贪心)
SGU 280.Trade centers 解题报告 题意: n(<=30000)个城市,(n-1)条道路,求最少需要选择多少个城市建造市场,使得所有城市到任意一个市场的距离不大于k. Solu ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- 20181009noip HZ EZ 两校联考trade(优先队列,贪心)
题面戳这里 思路: 裸的,贪心... 考场上写了一个数据分治(70ptsDP,30pts线段树优化贪心,GG了后30分) 这道题其实很简单的 我们看图: 我们在A时刻买一个东西,在B时刻卖出去,我们可 ...
随机推荐
- USACO 3.4 Raucous Rockers
Raucous Rockers You just inherited the rights to N (1 <= N <= 20) previously unreleased songs ...
- 清楚float浮动的四种方法
1.对父级设置适合CSS高度 对父级设置适合高度样式清除浮动,这里对“.divcss5”设置一定高度即可,一般设置高度需要能确定内容高度才能设置. 2.clear:both清除浮动 为了统一样式,我们 ...
- 关于mysql严格模式的开启、关闭
由于项目中对一些默认值设置问题,以及种种原因,mysql数据库需要使用非严格模式开发(mysql最近的版本默认是开启严格模式的). linux下mysql服务下操作步骤是: 1.进入mysql服务 ...
- servlet笔记,配置与 http相关
tomcat配置环境变量: JAVA_HOME= 指向你的jdk的主目录(bin目录的上一层) server.xml: <Context path="/myweb2&qu ...
- 本地存储 cookie,session,localstorage( 一)基本概念及原生API
http://www.w3school.com.cn/html5/html_5_webstorage.asp http://adamed.iteye.com/blog/1698740 localSto ...
- 基于C++的类编程总结
1. 类中public, protected, private这三个属性的区别: public意味着所有事物都能查询具有该属性的食物.(也即所有人可以在我不知情的情况下,查看我账户里还有多少钱). p ...
- ios版本更新总结
更新思路,获取APP Store 版本号与项目本地版本号对比,如果本地低于商店版本号,就提示用户更新(说明:在上架项目时请保持本地和商店版本号一致,避免检测更新问题被拒) 1.获取商店版本号,代码如下 ...
- 克隆git仓库中的一个分支
克隆git仓库中的某一个分支,可用如下命令: git clone -b <branch_name> <repo> 如:git clone -b hdcp_ree_tee_dev ...
- ASP.NET用户控件操作ASPX页面
定义一个不含数据的事件处理方法 用户控件 public event EventHandler Click; protected void Button1_Click(object sender, Ev ...
- C# 语言规范_版本5.0 (第7章 表达式)
1. 表达式 表达式是一个运算符和操作数的序列.本章定义语法.操作数和运算符的计算顺序以及表达式的含义. 1.1 表达式的分类 一个表达式可归类为下列类别之一: 值.每个值都有关联的类型. 变量.每个 ...