HDU-1009-FatMouse 'trade

Source: Internet
Author: User

 

FatMouse 'trade

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 33514 Accepted Submission (s): 10902

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

 

 

Code:

# Include "cstdio" # include "cstdlib" # include "algorithm" # include "iostream" using namespace std; typedef struct changeinfo {int j; int f;} changeinfo; // The structure of the room information, bool cmp (changeinfo a, changeinfo B) {return 1.0 *. j/. f> 1.0 * B. j/B. f; // multiply by 1.0 to make it double} int main () {int m, n, I, k; double sum; changeinfo a [1001]; while (scanf ("% d", & m, & n), (m + 1) & (n + 1) {sum = 0; for (I = 0; I <n; I ++) scanf ("% d", & a [I]. j, & a [I]. f); sort (A, a + n, cmp); // sort the values from large to small Based on the division result, the parameters are the first and last addresses involved in sorting and the cmp comparison function // for (I = 0; I <n; I ++) // printf ("% d \ n", a [I]. j, a [I]. f); if (m = 0) // =! The question must be considered in both cases before AC {for (I = 0; I <n; I ++) if (a [I]. f = 0) sum = sum + a [I]. j;} if (n = 0) sum = 0; if (m! = 0 & n! = 0) {for (I = 0, k = m; I <n, k> = 0; I ++) {if (a [I]. f> k) // sum = (1.0 * a [I]. j/a [I]. f) * k + sum; else sum = a [I]. j + sum; k = k-a [I]. f ;}} printf ("%. 3lf \ n ", sum);} return 0 ;}

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.