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 ...
随机推荐
- 总结前端JQ常用的一些操作手法(慢慢完善)
1.实例化Js一个object对象,把它当做类来用,事例是操作url的参数 function GetRequestCondition() { var url = window.location.hre ...
- Struts2中的校验框架
Struts2提供的客户端校验 尽管这种支持比较弱,但采用Struts2中的客户端校验时需要注意以下几点 1..将<s:form validate="true">的va ...
- yii2中的url美化
在yii2中,如果想实现类似于post/1,post/update/1之类的效果,官方文档已经有明确的说明 但是如果想把所有的controller都实现,这里采用yii1的方法 'rules' =&g ...
- DataSnap
一. DataSnap REST - http://docwiki.embarcadero.com/RADStudio/Berlin/en/DataSnap_REST 1. URI Mapping: ...
- django中使用json.dumps处理数据时,在前台遇到字符转义的问题
django后台代码: import json ctx['dormitory_list'] = json.dumps([{", "is_checked": 1}, {&q ...
- python:利用urllib查找计算机二级准考证号
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaYAAAEACAIAAAB3VkWnAAAgAElEQVR4nOydZ3gUR9bv+WhExhHnDH
- Nutch + solr 这个配合不错哦
因为朋友需要,所以把这个开源组合放在一起试用了下,正在弄,先Mark下. 用的是Nutch1.9,这个比较新,资料比较少,基本上就是用原来的英文WIKI. 首先要注意的是,不要试着在windows下做 ...
- 推荐的 CSS 书写顺序
//显示属性 display list-style position float clear //自身属性 width height margin padding border background ...
- SqlCommand类
一.常用属性 CommandText 获取或设置要对数据源执行的 Transact-SQL 语句.表名或存储过程. CommandTimeout 获取或设置在终止执行命令的尝试并生成错误之前的等待时间 ...
- C# Switch is Type
常规用法: Type t = sender.GetType(); if (t == typeof(Button)) { var realObj = (Button)sender; // Do Some ...