HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1009
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 92493 Accepted Submission(s): 32082
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.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max_v 1005
struct node
{
double v,c;
}p[max_v];
bool cmp(node a,node b)
{
return (a.v/a.c)>(b.v/b.c);
}
int main()
{
int m,n;
while(~scanf("%d %d",&m,&n))
{
if(n==-&&m==-)
break;
for(int i=;i<n;i++)
{
scanf("%lf %lf",&p[i].v,&p[i].c);
}
sort(p,p+n,cmp);
double sum=;
for(int i=;i<n;i++)
{
if(m>=p[i].c)
{
sum+=p[i].v;
m-=p[i].c;
}else
{
sum+=(m*(p[i].v/p[i].c));
break;
}
}
printf("%0.3lf\n",sum);
}
return ;
}
HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)的更多相关文章
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1009 FatMouse' Trade【贪心】
解题思路:一只老鼠共有m的猫粮,给出n个房间,每一间房间可以用f[i]的猫粮换取w[i]的豆,问老鼠最多能够获得豆的数量 sum 即每一间房间的豆的单价为v[i]=f[i]/w[i],要想买到最多的豆 ...
- [题解]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 (贪心)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题目大意:肥鼠准备了 磅的猫粮,准备和看管仓库的猫交易,仓库里装有他最喜爱的食物 豆.仓库有 个 ...
- HDU 1009 FatMouse' Trade (贪心算法)
题意:就是老鼠要用猫粮换粮食,第i个房间一些东西,要用东西去换,可以不全换.问给定的猫粮最多能换多少粮食. 析:贪心算法.我们先算出来每个房间物品的平均价格是多少,肯定越低越好,并且如果能全换就全换, ...
- 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(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- form表单在发送到服务器时候编码方式
enctype(编码方式):规定了form表单在发送到服务器时候编码方式.有如下的三个值可选: 1.application/x-www-form-urlencoded.默认的编码方式.但是在用文本的传 ...
- ApplicationContextInitializer接口
一.简述 ApplicationContextInitializer是Spring框架原有的概念, 这个类的主要目的就是在 ConfigurableApplicationContext类型(或者子类型 ...
- 13. Roman to Integer 罗马数字转化为阿拉伯数字(indexOf ()和 toCharArray())easy
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- SPDY和HTTP
SPDY 是什么 ? SPDY 是 Google 开发的基于传输控制协议 (TCP) 的应用层协议.SPDY 协议旨在通过压缩.多路复用和优先级来缩短网页的加载时间和提高安全性.(SPDY 是 Spe ...
- hdu 1712 (分组背包)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17676 这个问题让我对分组背包更清晰了一点,主要是这个问题: 使用一维数组的 ...
- SASS和SCSS标签详解与scoped局部和全局的使用
首先,学会使用sass: 1.先下载和安装node-sass和一些加载器 $ cnpm install sass-loader node-sass vue-style-loader --D 2.配置w ...
- 原生JS,运动的小人
今天突然想起来,不知道在什么网站上看的一个纯纯的原生JS写的效果,运动的小人,所以在这里给大家分享一下代码: 并说明:这不是本人写的,而是我在浏览网站是无意中发现的,现在已经不记得是哪个网站了,但是要 ...
- 基础架构之GitLab
Git几乎是软件开发人员的必备工具了,关于代码管理,公司都一般都会搭建自己的仓库,关于GitLab的详细介绍参见官方网站详见 https://about.gitlab.com,这篇文章主要介绍安装及使 ...
- C# Winform窗体和控件自适应大小
1.在项目中创建类AutoSizeForm AutoSizeForm.cs文件代码: using System; using System.Collections.Generic; using Sys ...
- Jmeter运营活动并发测试—巧用集合点
在运营活动测试过程中,经常需要对秒杀活动或定时抽奖活动进行并发测试.那么怎样快速便捷的模拟多用户同时参与活动,抽取奖品,进行并发测试呢?尤其是,当奖品总数N<用户总数M时,代码是否会存在奖品多发 ...