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): 93676 Accepted Submission(s): 32566
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.
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
31.500
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<memory.h>
#include<math.h>
#define eps 1e-7
using namespace std;
#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 n,m;
double sum;
int i;
while(cin>>m>>n)
{
if(n==-&&m==-)
break;
for(i=;i<n;i++)
cin>>p[i].v>>p[i].c;
sort(p,p+n,cmp);
sum=;
for(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) ...
- HDU 1009 FatMouse' Trade(简单贪心 物品可分割的背包问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1009 FatMouse' Trade Time Limit: 2000/1000 MS (Java/O ...
- FatMouse' Trade(杭电1009)
FatMouse' Trade Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tot ...
- 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) ...
- [题解]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(贪心)
FatMouse' Trade Problem Description FatMouse prepared M pounds of cat food, ready to trade with the ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- SQL语句整理(二) 数据定义语言DDL
前言: 这是我学数据库时整理的学习资料,基本上包括了所以的SQL语句的知识点. 我的教材是人大王珊老师的<数据库系统概论>. 因为是手打的,所以会用一些细节打错了,但都挺明显也不多(考完试 ...
- 响应式(2)——bootstrap的响应式
<meta name="viewport" content="width=device-width,user-scalable=no"/> < ...
- 小白学flask之hello,world
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "He ...
- window onload || jquery $()
1.window 的 onload 机制只指定一个函数,且在页面DOM及静态资源加载完之后执行: window.onload = function(){ alert(); } 2.$(document ...
- easyui grid 本地做分页
背景: 有的数据不是很多,但是有分页的需求,这个时候后台往往没有做分页,我们是一次请求了所有的数据. 代码: dataSource 为 grid 里的数据源 html部分: <table id= ...
- Django—XSS及CSRF
一.XSS 跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶意攻击者往W ...
- Linux基础之命令练习Day7-nginx,nfs
一. Nginx Nginx("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗 ...
- hdu 2063 过山车(模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Others) Me ...
- Hadoop自定义JobTracker和NameNode管理页面
为了可以方便地在hadoop的管理界面(namenode和jobtracker)中自定义展示项,使用代理servlet的方式实现了hadoop的管理界面. 首先, 在org.apache.hadoop ...
- SQL Server ->> 深入探讨SQL Server 2016新特性之 --- Row-Level Security(行级别安全控制)
SQL Server 2016 CPT3中包含了一个新特性叫Row Level Security(RLS),允许数据库管理员根据业务需要依据客户端执行脚本的一些特性控制客户端能够访问的数据行,比如,我 ...