FatMouse' 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
Output
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 【题意】一只老鼠有n的猫粮,一只猫有m间房,每间房有num的豆需要val的猫粮换取,求最大能换到的豆
【思路】简单的贪心问题
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N=+;
int n,m;
struct node
{
double num;
double val;
double p;
}a[N];
bool cmp(node a,node b)
{
return a.p>b.p;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(m==-&&n==-) break;
for(int i=;i<=m;i++)
{
scanf("%lf%lf",&a[i].num,&a[i].val);
a[i].p=1.0*a[i].num/a[i].val; }
sort(a+,a+m+,cmp);
double ans=;
for(int i=;i<=m;i++)
{
if(n==) break; if(a[i].val<=n)
{
n-=a[i].val;
ans+=a[i].num;
}
else
{
ans+=1.0*n*a[i].p;
break;
}
}
printf("%.3lf\n",ans);
}
return ;
}
FatMouse' Trade_贪心的更多相关文章
- 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> # ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 九度OJ 1433 FatMouse -- 贪心算法
题目地址:http://ac.jobdu.com/problem.php?pid=1433 题目描述: FatMouse prepared M pounds of cat food, ready to ...
随机推荐
- [问题2014A06] 复旦高等代数 I(14级)每周一题(第八教学周)
[问题2014A06] 若 \(n\) 阶实方阵 \(A\) 满足 \(AA'=I_n\), 则称为正交矩阵. 证明: 不存在 \(n\) 阶正交矩阵 \(A,B\) 满足 \(A^2=cAB+B^ ...
- 用jquery实现简单的表单验证
HTML代码: 1 <form action="" method="post" id="form-data"> 2 <di ...
- Caffe + Ubuntu 14.04 64bit + CUDA6.5 + 无GPU 配置
官网: http://caffe.berkeleyvision.org/installation.html#compilation 参考网站: http://www.cnblogs.com/dupul ...
- JPA入门案例详解(附源码)
1.新建JavaEE Persistence项目
- Java精确计算小数
Java在计算浮点数的时候,由于二进制无法精确表示0.1的值(就好比十进制无法精确表示1/3一样),所以一般会对小数格式化处理. 但是如果涉及到金钱的项目,一点点误差都不能有,必须使用精确运算的时候, ...
- static(静态、修饰符)
static(静态.修饰符) static修饰成员变量时:static修饰成员变量时,那么该成员变量的数据就是一个共享的数据. 静态成员变量的访问方式: 方式一: 使用对象进行访问. 对象.属性名 方 ...
- 微软2017校招笔试题2 composition
题目 Alice writes an English composition with a length of N characters. However, her teacher requires ...
- Android SharePreference 在主进程和次进程间共享数据不同步出错
SharedPreference作为android五大存储(网络,数据库,文件,SharedPreference,contentProvider)之中最方便使用的一个,从类名上来看就不是一个存储大 ...
- equals方法的小结
尽管经常使用equals,也可能理解不一定神,最近又要使用Collections.sort看到了这些,总结的不错. 首先equals方法必须满足自反性.对称性.传递性和一致性. 自反性(x.equal ...
- 优雅地在markdown插入图片
markdown 中插入图片,好烦!!! 喜欢用Markdown写文字,但是它的图片引用是一个大问题(当然csdn不会遇到这个问题).借用第三方将图片储存在印象笔记上是一个好办法.但是会出现的一个 ...