HDU 1009:FatMouse' Trade(简单贪心)
FatMouse' Trade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41982 Accepted Submission(s): 13962
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.
is followed by two -1's. All integers are not greater than 1000.
5 3
7 2
4 3
5 2
20 3
25 18
24 15
15 10
-1 -1
13.333
31.500
题意就是老鼠用猫粮换鼠粮。
。
。(Orz)。。
求它最多能换多少。。一道贪心水题。
。
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath> #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, n) for(int i=1; i<=n; i++) using namespace std; const int M = 1005;
int n, m;
double ans;
double t; struct node
{
double J;
double F;
double c;
}Q[M]; int cmp (node a, node b)
{
return a.c > b.c;
} int main()
{
while(scanf("%d%d", &n, &m)!=EOF)
{
ans = 0;
t = (double) n;
memset(Q, 0, sizeof(Q));
if(n==-1 && m==-1)
break;
f1(i, m)
{
scanf("%lf%lf", &Q[i].J, &Q[i].F);
Q[i].c = Q[i].J / Q[i].F;
}
sort(Q, Q+m, cmp);
f1(i, m)
{
if( Q[i].F<=t )
{
ans += Q[i].J;
t -= Q[i].F;
}
else
{
ans += t * Q[i].c;
break;
}
}
printf("%.3lf\n", ans);
} return 0;
}
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 ...
- 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(贪心基础题)
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 ...
随机推荐
- HDU 1711 Number Sequence【kmp求子串首次出现的位置】
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= ...
- Maven学习笔记2
Maven安装配置 1.下载Maven 官方地址:http://maven.apache.org/download.cgi 将下载的压缩包解压到你要安装 Maven 的文件夹.假设你解压缩到文件夹 – ...
- P3197越狱
花费了好长时间,终于刷掉了这道题. 题目在这里(洛谷) (信息学奥赛一本通) 嗯,没错,这是一道快速幂的题,不会快速幂点这里 好现在开始分析,这道题用小学奥数的思想就可以想到,直接算有多少种可能比较 ...
- leetcode122 Best Time to Buy and Sell Stock
题意:有一个数组,第i个数据代表的是第i天股票的价格,每天只能先卖出再买进(可以不卖出也可以不买进),求最大收益. 思路:自己去弄几个数组比划比划就知道了,比如[1,2,5,3,6],第一天买进,第二 ...
- Centos7下安装7za 及7za常用命令
安装必备环境 yum install kernel-devel kernel-headers gcc-c++ make bzip2 下载源码(16.02版本,2016.10.04 publish) w ...
- Exercise02_01
import java.util.Scanner; public class Out { public static void main(String[] args){ Scanner input = ...
- Java读取文本文件
try { // 防止文件建立或读取失败,用catch捕捉错误并打印,也可以throw StringBuilder stringBuilder = new StringBuilder(); // 读入 ...
- MySql优化--使用索引优化
原文:http://blog.csdn.net/zuoanyinxiang/article/details/50606837 1.索引优化的原理 在没有使用索引的时候,数据库系统会根据要查找的值到 ...
- [SpringMVC+redis]自定义aop注解实现控制器访问次数限制
原文:http://www.cnblogs.com/xiaoyangjia/p/3762150.html?utm_source=tuicool 我们需要根据IP去限制用户单位时间的访问次数,防止刷手机 ...
- iOS 中json解析数据出现中文乱码的问题
一般服务器的编码格式都是UTF8,这样通过json解析下来的的数据,一般中文是不会出现乱码,但是如果服务器的编码格式不是UTF8,通过json解析的数据中的中文容易出现luan乱码,怎么解决这个问题呢 ...