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 ...
随机推荐
- 01 日志组件XLog
本文地址为:http://www.cnblogs.com/ADTL/p/5357259.html XLog为XCode的日志组件,为系统基本功能. 使用示例: 1.新建WinForm程序 2.引用Ne ...
- Java线程状态:BLOCKED与WAITING的区别
Doc说明: /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in the blocked ...
- 课堂里学不到的C与C++那些事(一)
首先,声明一下这是一个系列的文章.至于整个系列有多少篇,笔者也不知道,不知道有多少篇,也不知道多久会更新一篇.反正只有一个原则,写出来的文 章能见得人才会公布出来.另外,我不是叫你逃课,而是觉得听课只 ...
- (原)vs2013编译boost1.60库
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5394236.html 参考网址: http://www.cnblogs.com/chuncn/arch ...
- PDO基础知识
使用PDO之前首先开启PHP的PDO扩展,方法见百度. PDO连接数据库的方式有三种 1.通过参数的形式连接数据库 (推荐) //通过参数形式连接数据库 try{ $dsn = 'mysql:host ...
- shell脚本分类
shell脚本分为三类:登录脚本.交互式脚本.非交互式脚本 一. 登录脚本类似于windows下的计算机设置中的登录脚本和账户设置下的登录脚本的合集(我是这么理解的哈). 其配置文件的关键词为pref ...
- html css 笔记
cursor其他取值 鼠标移入 auto :标准光标 default :标准箭头 pointer :手形光标 wait ...
- iOS开发之网络篇-CocoaPods的安装 EI Capitan 10.11 之前的方式
注意:此种方式,在苹果系统 EI Capitan 10.11 之前的版本,新版本有所不同 一.安装 1> 查看gem源 $ gem sources –l 2> 删除源 (因为本人是第N次 ...
- 子shell的$$
http://blog.csdn.net/firefoxbug/article/details/7426109
- Codeforces 494B Obsessive String
http://www.codeforces.com/problemset/problem/494/B 题意:给出两个串S,T,求有几种将S分成若干个子串,满足T都是这若干个子串的子串. 思路:f[n] ...