【HDU 1009】FatMouse' Trade
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
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
Sample Output
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,u;
double m,ans;
struct room
{
double j,f,p;
} r[];
int cmp(room a,room b)
{
return a.p>b.p;
}
int main()
{
while(scanf("%lf%d",&m,&n)&&n!=-&&m!=-)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&r[i].j,&r[i].f),
r[i].p=r[i].j/r[i].f;
sort(r,r+n,cmp);
u=ans=;
while(m&&u<n)
{
if(r[u].f>m) ans+=m*r[u].p,m=;
//剩下的猫粮不够把这个房间的咖啡豆换过来,那就能换多少换多少
else ans+=r[u].j,m-=r[u].f;
//够的话,这间房子全部咖啡豆换过来
u++;
}
// while(m>=r[u].f&&u<n) //换种写法
// {
// ans+=r[u].j;
// m-=r[u].f;
// u++;
// }
// if(u!=n) ans+=m*r[u].p;
printf("%.3lf\n",ans); }
return ;
}
【HDU 1009】FatMouse' Trade的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDOJ 1009】 CRB and String
[HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- HDU 1009:FatMouse' Trade(简单贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
随机推荐
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...
- Unity开发 资源准备
开发环境准备 插件资源 当有喜欢的资源,选择去泽国社区和纳金网下载,仅用于学习目的. Fbx查看器 下载版本对应的FBX插件 比如:fbx20133_quicktime_win.exe 对应Quick ...
- ubuntu手贱改了sudoers权限之后的恢复
sudo 这个命令是ubuntu系统是用的最多的(和其他大众版linux系统比起来),而一个普通用户是否有sudo权限来临时切换到root用户来执行“一行”命令取决于 /etc/sudoers的配置, ...
- 准备写一些读书笔记,最近在填坑 SQL学习指南 Spring in Action effective Java
把一些读书的理解通过白板图的形式展示出来,加深自己的认识, 因为目前没有工程项目练手,暂时在学习中把这些知识深化认识一下
- this关键字的使用
一,表示类中属性 1,没有使用this的情况 class Person{ // 定义Person类 private String name ; // 姓名 private int age ; // 年 ...
- window7 右键菜单显示-》在此处打开命令窗口
window7 右键菜单显示->在此处打开命令窗口: 注册表中: HKEY_CLASSES_ROOT\Directory\Background\shell\cmd下将[Extended]重命名或 ...
- Netty开发UDP协议
UdpServer package org.zln.netty.five.part07; import io.netty.bootstrap.Bootstrap; import io.netty.ch ...
- jqXHR 对象(post完成后再调用函数)
场景: function A() { B(); C(); } function B() { $.post(url, {}, function () { alert("我错了!"); ...
- Node.js之事件events
Events a.EventEmitter支持多个事件监听,最大为10,也可以自定义最大数 //添加监听var EventEmitter = require('events').EventEmitte ...
- Log4net Dll用法
在导入Log4net的过程中,遇到一两个小bug. 开发平台必须是NET4 而不能是net4 client profile Log4Helper 里面的Namespace要和我们建立项目的名称一致. ...