Fatmouse 'trade (hangdian 1009)

Source: Internet
Author: User
Fatmouse 'tradetime limit: 2000/1000 ms (Java/other) memory limit: 65536/32768 K (Java/other) total submission (s): 1 accepted submission (s): 1 Font: times New Roman | verdana | georgiafont size: Regular → problem descriptionfatmouse 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.
Inputthe 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.
Outputfor 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 37 24 35 220 325 1824 1515 10-1 -1
Sample output
13.33331.500
// This question is a simple greedy question. It means that a mouse has a cat grain in the M-listed list. Data [I] is sent to the cat food. B can be exchanged for data [I]. a. How much food can I redeem at most. // Simply sort the values of data [I]. A/data [I]. B in ascending order to solve the problem. # Include <stdio. h> struct st {double A; Double B; double C;} data [1000]; int main () {int I, j, M, N; struct st data [1000], T; while (scanf ("% d", & M, & N) & (M! =-1 | n! =-1) {double sum = 0.000; for (I = 0; I <n; I ++) {scanf ("% lf ", & Data [I]. a, & Data [I]. b) ;}for (I = 0; I <n; I ++) {for (j = I + 1; j <n; j ++) {If (data [I]. a/data [I]. b) <data [J]. a/data [J]. b) {T = data [I]; data [I] = data [J]; data [J] = T ;}}for (I = 0; I <N; I ++) {If (m-data [I]. B >=0.001) {sum + = data [I]. a; m-= data [I]. b;} else {sum = sum + M * Data [I]. a/data [I]. b; break ;}} printf ("%. 3lf \ n ", sum);} return 0 ;}


Fatmouse 'trade (hangdian 1009)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.