zsc_寒假训练 3

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

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     int m,n;
 9     int f[1200],j[1200];
10     double a[1200],b[1200];
11     int next[1000];
12     while((scanf("%d%d",&m,&n)&&(m!=-1||n!=-1)))
13     {
14         for(int i=0;i<n;i++)
15         {
16             scanf("%d%d",&f[i],&j[i]);
17             a[i]=1.0*f[i]/j[i];
18         }
19         double num=0;
20         for(int i=0;i<n;i++)
21         {
22             for(int k=i+1;k<n;k++)
23             {
24                 if(a[i]<a[k])
25                 {
26                     swap(a[i],a[k]);
27                     swap(f[i],f[k]);
28                     swap(j[i],j[k]);
29                 }
30             }
31             if(j[i]<m)
32             {
33                 num+=f[i];
34                 m-=j[i];
35             }
36             else
37             {
38
39                 num+=1.0*f[i]*m/j[i];
40                 m=0;
41             }
42             if(m==0)
43             {
44                 break;
45             }
46         }
47         printf("%.3lf\n",num);
48     }
49 }

时间: 2024-12-09 18:42:23

zsc_寒假训练 3的相关文章

zsc_寒假训练 8

Description Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him? Given a positive integers Y which indicate the start year, and a positive integer N, your task is to tell the Nth leap year from

zsc_寒假训练 5

Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that

zsc_寒假训练 7

Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the input is a s

zsc_寒假训练 6

Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting

zsc_寒假训练 4

Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights. Give you some integers, your task is to sort these number ascend

zsc_寒假训练 9

Description “Point, point, life of student!” This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course. There are 5 problems i

常州大学新生寒假训练会试 题解

[题目链接] A - 添加逗号 注意是从后往前三个三个加逗号,最前面不允许有逗号 #include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; char s[maxn]; char ans[maxn]; int sz; int main() { scanf("%s", s); int len = strlen(s); sz = 0; int t = 0; for(int i = len -

FZU ICPC 2020 寒假训练 4 —— 模拟(一)

P1042 乒乓球 题目背景 国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及.其中11分制改革引起了很大的争议,有一部分球员因为无法适应新规则只能选择退役.华华就是其中一位,他退役之后走上了乒乓球研究工作,意图弄明白11分制和21分制对选手的不同影响.在开展他的研究之前,他首先需要对他多年比赛的统计数据进行一些分析,所以需要你的帮忙. 题目描述 华华通过以下方式进行分析,首先将比赛每个球的胜负列成一张表,然后分别计算在11分制和21分制下,双方的比赛结果(

FJUT2017寒假训练二题解

A题 题意:让你找出唯一的一个四位数,满足对话时的要求. 思路:因为是4位数,可以直接从1000-9999遍历一遍,判断是否有唯一的数能满足所有条件,如果不是唯一的或者没有满足条件的数就输出Not sure.特别丑的代码附上... 1 #include<stdio.h> 2 int a[10000],b[10000],c[10000]; 3 int main() 4 { 5 int n; 6 while(~scanf("%d",&n)) 7 { 8 if(n==0)