CDZSC_2015寒假新人(1)——基础 c
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<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int m,n;
int f[],j[];
double a[],b[];
int next[];
while((scanf("%d%d",&m,&n)&&(m!=-||n!=-)))
{
for(int i=;i<n;i++)
{
scanf("%d%d",&f[i],&j[i]);
a[i]=1.0*f[i]/j[i];
}
double num=;
for(int i=;i<n;i++)
{
for(int k=i+;k<n;k++)
{
if(a[i]<a[k])
{
swap(a[i],a[k]);
swap(f[i],f[k]);
swap(j[i],j[k]);
}
}
if(j[i]<m)
{
num+=f[i];
m-=j[i];
}
else
{ num+=1.0*f[i]*m/j[i];
m=;
}
if(m==)
{
break;
}
}
printf("%.3lf\n",num);
}
}
CDZSC_2015寒假新人(1)——基础 c的更多相关文章
- CDZSC_2015寒假新人(1)——基础 i
		
Description “Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you mus ...
 - CDZSC_2015寒假新人(1)——基础 h
		
Description Ignatius was born in a leap year, so he want to know when he could hold his birthday par ...
 - CDZSC_2015寒假新人(1)——基础 g
		
Description Ignatius likes to write words in reverse way. Given a single line of text which is writt ...
 - CDZSC_2015寒假新人(1)——基础 f
		
Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u i ...
 - CDZSC_2015寒假新人(1)——基础 e
		
Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...
 - CDZSC_2015寒假新人(1)——基础 d
		
Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It i ...
 - CDZSC_2015寒假新人(1)——基础 b
		
Description The highest building in our city has only one elevator. A request list is made up with N ...
 - CDZSC_2015寒假新人(1)——基础 a
		
Description Contest time again! How excited it is to see balloons floating around. But to tell you a ...
 - CDZSC_2015寒假新人(2)——数学 P
		
P - P Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
 
随机推荐
- 【Solr专题之九】SolrJ教程
			
一.SolrJ基础 1.相关资料 API:http://lucene.apache.org/solr/4_9_0/solr-solrj/ apache_solr_ref_guide_4.9.pdf:C ...
 - LInux系统的C语言开发工具笔记
			
常用的C语言开发工具有很多,每个开发工具所支持的库函数和对标准的实现都有差异.对于初学者,选择一款使用广泛.上手容易的开发工具才是王道.在Windows 上很多从事C和C++开发的人员都选择VS作为开 ...
 - 【ASP.NET MVC路由测试+性能调试工具】
			
http://getglimpse.com https://github.com/Glimpse/Glimpse 百度网盘: http://pan.baidu.com/s/1jHuTtKa
 - xargs mv命令使用方法:ls  *.mp3 |xargs -i  mv {} /tmp
			
ls *.mp3 |xargs -i mv {} /tmp 或者 find . -name "*.mp3" -exec mv {} /tmp \;
 - 经典递归算法研究:hanoi塔的理解与实现
			
关于hanoi塔的原理以及概念,请Google,访问不了去百度. 主要设计到C中程序设计中递归的实现: 主代码实现如下: void hanoi(int src, int dest, int tmp, ...
 - 百度地图LV1.5实践项目开发工具类bmap.util.jsV1.0
			
/** * 百度地图使用工具类-v1.5 * * @author boonya * @date 2013-7-7 * @address Chengdu,Sichuan,China * @email b ...
 - UESTC_秋实大哥下棋 2015 UESTC Training for Data Structures<Problem I>
			
I - 秋实大哥下棋 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
 - python 性能优化
			
1.优化循环 循环之外能做的事不要放在循环内,比如下面的优化可以快一倍 2.使用join合并迭代器中的字符串 join对于累加的方式,有大约5倍的提升 3.使用if is 使用if is True比i ...
 - #include<math.h>
			
1.sin(a)类:a是弧度值: 2.abs(b):结果是b的绝对值: 3.exp(c):exp()用来计算以e为底的x次方值,即ex值,然后将结果返回.返回值: 返回e的x次方计算结果. 4.log ...
 - JS~delegate与live
			
在jquery里有两个方法可以用来绑定自动追加出来的DOM对象,它们是live和delegate,事实上,这两个方法是bind方法的一个变体,在对于固定DOM对象时,我们通常使用bind就可以了,而对 ...