1009 FatMouse' Trade

杭电ACM OJ 1009 FatMouse' Trade 简单的贪心算法 入门级 翻译好题目就能做出来 FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 82705    Accepted Submission(s): 28651 Problem Description FatMouse 阅读详情

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

题目说的是非负数,那么输入的就有可能是0

第15行就是要解决N为0的情况。

第8行的后面是> >,中间有空格,不然OJ编译有错误!

#include <iostream>
#include <map>
#include <iomanip>
using namespace std;
int main()
{
	pair<int,int> pd;
	pair<double,pair<int,int> > pp;
	multimap<double,pair<int,int> > mymap;
	multimap<double,pair<int,int> >::reverse_iterator pos;
	int M,N,j;
	double sum;
	while (cin>>M>>N&&(M!=-1&&N!=-1))
	{
		if (N==0)
		{
			cout<<"0.000"<<endl;
			continue;
		}
		j=0;
		while (j<N)
		{
			cin>>pd.first>>pd.second;
			pp.first=(double)((double)pd.first/(double)pd.second);
			pp.second=pd;
			mymap.insert(pp);
			++j;
		}
		pos=mymap.rbegin();
		sum=0.0000;
		while (M>0)
		{
			if (M>=pos->second.second)
			{
				sum+=(pos->second.first);
				M-=(pos->second.second);
				++pos;
			}
			else
			{
				sum+=((double)M)*pos->first;
				break;
			}
		}
		cout<<fixed<<setprecision(3)<<sum<<endl;
		mymap.clear();
	}
	return 0;
}


CMake、Make、MinGw、Clang、Llvm、GCC、MSVC的区别 除开 GCC (GNU 编译器集合) 以外,MinGW 还包含有一些其他的 GNU 程序开发工具;的缩写,MinGw是windows版本的gcc集合。并不仅是一个 C/C++ 编译器,而是一套。是微软开发的VC运行时库,3、Make和CMake是。 阅读详情

相关推荐

STM32CubeMX | HAL库实战:ADC多通道采集模式深度解析(轮询、DMA、TIM触发)

本文深度解析了基于STM32CubeMX与HAL库实现ADC多通道数据采集的三种核心模式:轮询、DMA以及TIM触发DMA。文章通过对比分析,详细阐述了各模式的配置要点、适用场景与潜在陷阱,旨在帮助开发者根据实时性、CPU占用及采样精度等需求,选择并实现高效稳定的多通道数据采集方案。

postgres8guard的博客 971

数学—杭电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): 39812    Accepted Submission(

笨鸟 772

保姆级教程:用YOLOv5s训练PCB缺陷检测模型(附北大公开数据集)

本文提供了一份基于YOLOv5s的PCB缺陷检测模型从零开始的完整实战教程。详细解析了如何使用北大公开数据集,涵盖环境搭建、数据处理、模型训练、性能评估及优化部署全流程,并针对工业场景中常见的类别不均衡问题给出了具体解决方案,旨在帮助开发者快速构建高精度的自动化质检系统。

weixin_28285943的博客 306

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...

你呢的博客 717

Ubuntu 24.04下Loki+Alloy+Grafana日志分析系统的快速部署与实践

本文详细介绍了在Ubuntu 24.04系统上快速部署Loki+Alloy+Grafana轻量级日志分析系统的完整流程。通过二进制安装Loki、配置Alloy采集器以及设置Grafana可视化界面,构建了一套资源消耗低、易于管理的日志解决方案,并实战演示了如何采集和分析网络设备日志,特别适合资源有限的中小团队或边缘计算场景。

tensor9flow的博客 233

树莓派4B系统安装及SSH远程控制(简单易操作)

​自从2022年4月树莓派官网更新了RaspberryPiImager版本v1.7.2后,便不再支持自行建立ssh文件,并用默认用户名pi和密码raspberry的方式进行远程控制(亲测不行,输密码时一直access denied)。但是该版本软件提供了烧录系统前设置ssh用户及密码功能。本文记录了系统安装和SSH远程操作步骤。........................

机械人的代码路 5789

杭电1009 FatMouse' Trade

/********************************  *    日期:2011-2-7  *    作者:SJF  *    题号:杭电1009  *  题目:FatMouse' Trade  *    结果:AC  ********************************/ #include #include /*int cmp(const void

落日小屋 876

Unity之Timeline教程

Unity Timeline是Unity的一种时间轴编辑器工具,用于制作和管理游戏中的动画、剧情以及事件触发。它提供了直观的界面,使得开发者可以通过拖放操作轻松创建和编辑时间轴。Activation Track:用于控制物体的激活状态。可以在轨道上添加关键帧,控制物体的激活和非激活状态。Animation Track:用于处理物体的动画。可以在此轨道上添加关键帧,编辑物体的动画状态。Audio Track:用于处理场景中的音频。可以管理音频的播放、暂停、淡入淡出等操作。

TxNet 9436

杭电 1009 FatMouse' Trade

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

逸疏 903

计算机组成原理(第三版)唐朔飞-第八章CPU的结构和功能-课后习题

8.1CPU有哪些功能?画出其结构框图并简要说明每个部件的作用。

weixin_45735391的博客 6万+

C++性能优化:深入理解缓存一致性与伪共享

在现代多核处理器的世界里,理解缓存一致性和伪共享就像理解一个复杂社会系统的运作规则。正如心理学家阿德勒所说:"人的行为总是有目的的",CPU缓存的每一次同步也都有其深层的硬件逻辑。本文将带你深入探索这些看不见的性能杀手,以及如何在实际项目中与它们优雅共处。

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 933

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 375

066、AR 应用中虚拟物体漂移抖动?IMU 融合 + 光流追踪的视觉里程计优化方案

AR应用中虚拟物体漂移抖动优化方案 摘要:针对AR应用中虚拟物体漂移抖动问题,提出一种IMU融合与光流追踪的视觉里程计优化方案。关键点包括:1) 采用IMU预积分技术处理高频噪声,通过中值积分计算帧间相对运动约束;2) 使用金字塔LK光流追踪像素运动,通过中值偏差法剔除异常值;3) 构建10帧滑动窗口的紧耦合优化框架,将IMU预积分约束和光流重投影约束联合优化。实验表明,该方法有效解决了时间戳未对齐导致的"跳舞箭头"现象,在手机端实现稳定30fps的AR定位精度,漂移误差降低至厘米级。特别提醒:IMU与视觉

ai技术增长的博客 161

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

hdu 1009 FatMouse' Trade

链接:hdu 1009

happy_lcj 633

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

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的技术交流栈 825

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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

HDOJ FatMouse' Trade JAVA 1009

简单的贪心问题 但不知道为什么 用Decimal输出的不能AC  只能用printf的格式输出,AC了 package _1009; import java.text.DecimalFormat; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.uti

董公子的博客 303

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 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的博客 470

『杭电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 cont...

漠宸离若的博客 358

杭电hd 1009 FatMouse' Trade

这是一道类背包问题的贪心算法题,代码写的不是很干练,学习中,一起进步了。 import java.util.Scanner; //类背包问题 public class Hd1009 { public static void main(String[] args){  Scanner sc=new Scanner(System.in);    while(sc.hasNext()){

Zhongyou2010的专栏 560

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

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)

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...

名字呢? 530
上一篇: 1003
下一篇: 1010 Tempter of the Bone
游刃有余则成
博客等级 码龄17年 24粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值