HDU1009 FatMouse' Trade

1009 FatMouse’ Trade 简单贪心算法 FatMouse' Trade                                               Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description FatMouse prepared M 阅读详情
Problem Description
FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.
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
The input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.
 

Output
For each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.
 

Sample Input
5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1
 

Sample Output
13.333 31.500
 

贪心算法:
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#include <queue>

struct Food{
	int J;
	int F;
}food[1005];

int cmp(const void *a,const void *b){
	Food *f1=(Food *)a;
	Food *f2=(Food *)b;
	return f1->F*f2->J-f1->J*f2->F;
}
int main()
{
	freopen("C:\\in.txt","r",stdin);
	int M,N;
	while(scanf("%d %d",&M,&N)!=EOF){
		if(M==-1&&N==-1)break;
		for(int i=1;i<=N;i++){
			scanf("%d %d",&food[i].J,&food[i].F);
		}
		qsort(food+1,N,sizeof(food[0]),cmp);
		
		double sum=0;
		for(int i=1;i<=N;i++){
			if(M<food[i].F){
				sum+=M*1.0/food[i].F*food[i].J;
				break;
			}
			else{
				M-=food[i].F;
				sum+=food[i].J;
			}
		}
		printf("%.3f\n",sum);
	}
	return 0;
}


spring boot 集成cas(一) 服务端搭建 简单点就是统一服务认证,多个系统一次登录。俗称单点登录。 阅读详情

相关推荐

【HDR】曝光融合(Exposure Fusion)

在曝光融合(Exposure Fusion)算法问世之前,多曝光序列合成用于显示的HDR需要两个步骤,第一步是将多张不同曝光的低动态范围图像合成为HDR(例如Debevec提出的加权融合方法),通常HDR为12bit或者16bit;第二步是通过tonemapping对高动态范围HDR进行压缩以支持低动态范围显示设备(例如Durand提出的基于双边滤波的tonemapping算法),一般会压缩至8bit。

专注人工智能,主攻CV 1万+

HDU-1009(FatMouse' Trade)

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room contain...

名字呢? 531

麒麟信安3.3-6C电网版虚拟机安装避坑指南:从ISO下载到SSH配置全流程

本文提供麒麟信安3.3-6C电网版虚拟机的详细安装与配置指南。针对电力行业仿真测试需求,重点解析从ISO镜像获取、虚拟机环境准备、安装过程中的三大“雷区”(如多管理员密码逻辑、分区方案、网络配置)到首次启动后的网络、SSH及root策略配置的全流程避坑要点,帮助技术人员高效、安全地完成部署。

rainy的博客 862

FatMouse' Trade hdu1009 贪心算法

http://acm.hdu.edu.cn/showproblem.php?pid=1009 开始贪心专题。 题意:一共有n个房子,每个房子里有老鼠喜欢吃的javabeans,但是每个房间里的javabeans的价格不一样。老鼠用m元,问m元最多可以卖多少javabeans,其中每个房间里的javabeans可以被分割。 先求单价,然后排个序就行了。 #include #include

operator456的专栏 5975

Python实战:逐笔高频因子构建与回测全流程解析

本文详细解析了使用Python构建与回测逐笔高频因子的全流程。从逐笔数据的价值与清洗入手,通过实战代码演示了‘大买成交金额占比’因子的计算逻辑,并重点阐述了因子正交化处理的重要性以剔除风格影响。最后,提供了一个经典的分位数回测框架来验证因子有效性,并分享了数据质量、计算效率与过拟合等核心避坑指南。

grass的博客 402

用KalmanNet搞定非线性状态估计:当卡尔曼滤波遇上神经网络

本文深入探讨了KalmanNet如何将神经网络与卡尔曼滤波结合,以解决非线性状态估计中的模型失配和噪声不确定性问题。通过保留经典滤波框架并用RNN学习卡尔曼增益,该方法在无人机导航、机器人定位等场景中实现了模型驱动与数据驱动的优势互补,提升了估计的鲁棒性和灵活性。

mango的博客 318

HDU 1009 FatMouse' Trade题解

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room con

靖空间 2710

VerilogEval实战指南:从基准测试到模型微调的全流程解析

本文提供了VerilogEval实战指南,详细解析了从基准测试到模型微调的全流程。VerilogEval是一个自动化、标准化的测试框架,用于客观评估大语言模型生成Verilog硬件代码的能力。文章涵盖了环境搭建、核心机制解析、利用其生成合成数据进行模型微调的策略,以及如何将其工程化集成到自动化评估流程中,为硬件设计领域的AI应用提供了完整的方法论。

yy01234的博客 1007

HDU1009:FatMouse' Trade

Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room conta

ACM!荣耀之路! 7958

openbmc mctp i3c适配步骤

本文介绍了在Intel OKS平台下,BMC作为I3C从设备如何适配MCTP over I3C的实现方法。主要内容包括:1)关键术语解释,如MDB(Mandatory Data Byte)值为0xAE,DCR(Device Characteristics Register)和BCR(Bus Characteristics Register)的设置;2)适配流程说明,包括BMC作为控制器主节点分配地址后成为MCTP端点,CPU作为总线所有者的角色转换;3)测试验证步骤,展示通过mctp-client工具发送指

wit_yuan的专栏 151

使用MATLAB结合EasySpin进行ESR模拟的详细步骤及示例代码

安装EasySpin:确保你已经安装了EasySpin工具箱,它可以帮助你进行ESR模拟。你可以从EasySpin的官方网站(https://easyspin.org/)下载并安装。准备实验数据:将实验得到的EPR数据整理成合适的格式,一般包含磁场(Magnetic Field)和信号强度(Intensity)两列。进行模拟:使用EasySpin的函数对单线态氧自由基和超氧自由基进行模拟。调整参数:通过调整模拟参数,使模拟得到的峰型和峰位置与实验数据尽可能匹配。导出数据。

AI的内部世界的博客 2013

HDU-1009 FatMouse' Trade

HDU 1009 FatMouse’ Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room...

你呢的博客 718

C和C++Everything教程的简介

C和C++Everything教程的简介 C和C++Everything教程,该专栏目前已有8000博文,订阅该专栏相当于同时订阅以下所有收费专栏

希望我的博客,能帮上你解决学习中工作中所遇到的问题 4404

hdu 1009 FatMouse' Trade

链接:hdu 1009

happy_lcj 633

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

HDU.1009 FatMouse' Trade

文章目录一、题目解读1、原题2、分类3、题意4、输入输出格式5、数据范围二、题解参考1、总体思路2、思路①(1).分析(2).一些数据(3).AC代码三、评价与后话1、评价2、G++的坑3、后话 一、题目解读 1、原题 HDU.1009 FatMouse’ Trade 2、分类 贪心 背包——多重背包 3、题意 老鼠有MMM个猫币,猫有鼠币NNN堆(每堆数量为JiJ_iJi​)、并为每一堆提供...

God-Excious的博客 487

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

hdu 1009 FatMouse' Trade

hdu  1009  FatMouse' Trade         题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 贪心入门 题目大意:fat mouse跟cat做生意,市场上有很多间屋,每个屋里都有一定数量的javabean--fat mouse爱吃的东西,需要用fat mouse手中的猫粮来交换,换完为止。 题目分析:贪心思想,按

slicer的技术交流栈 826

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU 1009 FatMouse' Trade

FatMouse’ Trade 原题链接 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 95691 Accepted Submission(s): 33343 Problem Description FatMouse prepar...

Sword Art Online 376

HDU1009 FatMouse' Trade 【贪心】

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 42786    Accepted Submission(s): 14274 Problem Description FatMouse p

长风的专栏 897

HDU 1009 FatMouse' Trade 详解

FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean. The warehouse has N rooms. The i-th room c

shangyuexi的博客 471

hdu1009 FatMouse' Trade

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1009 译文: 题目描述:       从前有只肥肥的老鼠,他叫FatMouse,他就像人类的恐怖分子跟敌人交易军火一样, 猥琐的他准备了M磅猫食,准备与守卫仓库的大猫们进行交易,仓库里有他最爱吃的食物Javabean。 仓库里有N个房间,第i间房间里有J[i]磅Javabean且需要F[i]

Enstein_Jun 1616

Hdu 1009 FatMouse' Trade

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 59355    Accepted Submission(s): 19916 Problem Description FatMouse

曾经沧海难为水,除却巫山不是云 450

贪心/hdu 1009 FatMouse' Trade

题意   有n种物品,每一种需要不同的消费,现在手里有m块钱,求问最多可以买多少 分析   贪心   把每一种物品的价格算出来,然后sort一下,按照价格从便宜到贵排序,能买多少买多少,买买买! Accepted Code 1 /* 2 PROBLEM:hdu1009 3 AUTHER:Nicole Lam 4 MEMO:贪心 5...

diyoucang7967的博客 150

hdu-1009 FatMouse' Trade

Problem Description: FatMouse准备了M磅的Cat-Food,以便用来跟小Cat交换好吃的JavaBean。 现在有N个房间,第i个房间有J[i]磅的JavaBean,其交换的筹码是F[i]磅的Cat-Food。 当然,FatMouse还是有很大的选择权的,对任意一个房间,它可以只交换一部分的Cat-Food。 现要求FatMouse以怎样的策

qq_31580579的博客 274
上一篇: 数学问题集锦
下一篇: HDU1257 最少拦截系统
_王川
博客等级 码龄16年 68粉丝 411原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值