CDZSC_2015寒假新人(1)——基础 C

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

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct laoshu
{
    int j;
    int f;
    double s;
};
bool cmp(laoshu stud1,laoshu stud2)
{
    return stud1.s>stud2.s;
}
int main()
{
#ifdef CDZSC_OFFLINE
    freopen("in.txt","r",stdin);
#endif
    int i,m,n;
    double sum;
    laoshu stud[1010];
    while(scanf("%d%d",&m,&n)&&m!=-1&&n!=-1)
    {
        sum=0;
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&stud[i].j,&stud[i].f);
            stud[i].s=1.0*stud[i].j/stud[i].f;
        }
        sort(stud,stud+n,cmp);
        for(i=0; i<n; i++)
        {
            if(m>=stud[i].f)
            {
                sum+=stud[i].j;
                m-=stud[i].f;
            }
            else
            {
                sum+=stud[i].s*m;
                break;
            }
        }
        printf("%.3lf\n",sum);
    }
    return 0;
}
时间: 2024-08-02 21:07:57

CDZSC_2015寒假新人(1)——基础 C的相关文章

CDZSC_2015寒假新人(1)——基础 I

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

CDZSC_2015寒假新人(1)——基础 B

Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor

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

CDZSC_2015寒假新人(1)——基础 G

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

CDZSC_2015寒假新人(1)——基础 E

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

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

CDZSC_2015寒假新人(1)——基础 H

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 ye

CDZSC_2015寒假新人(2)——数学 - O

Description 当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数. 如果一个正整数m表示成二进制,它的位数为n(不包含前导0),寒月称它为一个n二进制数.所有的n二进制数中,1的总个数被称为n对应的月之数. 例如,3二进制数总共有4个,分别是4(100).5(101).6(110).7(111),他们中1的个数一共是1+2+2+3=8,所以3对应的月之数就是8. Input 给你一个整数T,表示输入数据的组数,接下来有T行,每

CDZSC_2015寒假新人(4)——搜索 A

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and