hdu 1009 贪心基础题
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
31.500
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
using namespace std;
struct nod
{
double c;
double v;
double s;
};
const int maxn=1000+10;
nod java[maxn];
bool cmp(nod a,nod b)
{
return a.s>b.s;
}
int main()
{
int n,i;
double m,k;
while(scanf("%lf%d",&m,&n)&&(m!=-1||n!=-1))
{
double k=0;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&java[i].v,&java[i].c);
java[i].s=java[i].v/java[i].c;
}
sort(java,java+n,cmp);
for( i=0;i<=n-1;i++)
{
if(m>=java[i].c)
{
m-=java[i].c;
k+=java[i].v;
}
else
{
k+=(double)m/java[i].c*java[i].v;
break;
}
}
printf("%.3lf\n",k);
}
return 0;
}
hdu 1009 贪心基础题的更多相关文章
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- 洛谷P5019 铺设道路 题解 模拟/贪心基础题
题目链接:https://www.luogu.org/problemnew/show/P5019 这道题目是一道模拟题,但是它有一点贪心的思想. 我们假设当前最大的深度是 \(d\) ,那么我们需要把 ...
- hdu 2845(dp基础题)
题意:容易理解. 分析:以后碰到这种类型的题,就要考虑把矩阵先按行来处理,再按列处理.先算出每行能够能够得到的最大值,然后按列处理即可. 代码实现: #include<stdio.h> # ...
- hdu 1009 贪心算法
博主英语不好,看懂个大概,老鼠有M磅猫食.有N个房间,每个房间前有一只猫,房间里有老鼠最喜欢的食品JavaBean,J[i].若要引开猫,必须付出相应的猫食F[i]. 当然这只老鼠没必要每次都付出所有 ...
- hdu 1847 博弈基础题 SG函数 或者规律2种方法
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 6047 贪心思维题
Maximum Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 1009 FatMouse' Trade (贪心)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题目大意:肥鼠准备了 磅的猫粮,准备和看管仓库的猫交易,仓库里装有他最喜爱的食物 豆.仓库有 个 ...
- HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
双向边,基础题,最小生成树 题目 同题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...
随机推荐
- 011_hasCycle
/* * Author :SJQ * * Time :2014-07-16-20.21 * */ #include <iostream> #include <cstdio> # ...
- JavaScript学习笔记(三十八) 复制属性继承
复制属性继承(Inheritance by Copying Properties) 让我们看一下另一个继承模式—复制属性继承(inheritance by copying properties).在这 ...
- html+css布局小练习w3cfuns
虽然花了很长时间,但是也知道了不少,这次也不像以前了,不知道怎么下手,虽然是照着图片做,不过也做出来了图片来自w3cfuns:网站图片url 看了w3cfuns的两天驾驭DIV+CSS 这个网站对新 ...
- Java学习笔记--HashMap中使用object做key的问题【转】
在HashMap中,如果需要使用多个属性组合作为key,可以将这几个属性组合成一个对象作为key.但是存在的问题是,要做get时,往往没办法保存当初put操作时的key object的referenc ...
- Eclipse项目导入Android Stuio 配置出现 Timeout waiting to lock buildscript class cache for build file 'H:\studioproject\Generic_SN\build.gradle'
Eclipse项目导入Android Stuio 配置出现 Error:Timeout waiting to lock buildscript class cache for build file ...
- 编译cwm-recovery(含部分修改步骤)[转]
1. 同步cm10.1的源码,具体操作请百度之-- 2. 打开终端,到源码目录下: cd Android/cm10.1 //我的源码目录 3. 如果不想使用cm10 ...
- maven配置文件解析
maven2配置文件主要分为settings.xml与pom.xml两种,下面将逐一介绍. ===================================settings.xml======= ...
- ServletConfig对象 【通过此对象获取到web.xml中的信息】
用途: 1)想让当前的Servlet读取一些在web.xml文件配置的初始化参数时, 可以使用ServletConfig对象,他是Servlet运 ...
- ural 1586. Threeprime Numbers
这道题看着别人的代码写的. #include <cstdio> #include <cstring> #define m 1000000009 using namespace ...
- C#使用.net.mail配置163邮箱报错:不允许使用邮箱名称。 服务器响应为:authentication is required,smtp9,DcCowABHK4UYE11W2k6fAQ--.52196S2 1448940312
client.UseDefaultCredentials = true; 要放在 client.Credentials = new NetworkCredential("用户名", ...