HDU acmsteps 1.3.7 mourn the victims of the 512 Wenchuan earthquake-the old man is really hungry

Source: Internet
Author: User
1 # Include <iostream> 2 # Include <algorithm> 3 # Include <iomanip> 4   Using   Namespace  STD;  5   Const   Int Maxn = 1000  ;  6   Struct  Rice { 7       Int  P, h;  8   };  9   Rice rice [maxn];  10   Bool Mycomp ( Const Rice &, Const Rice & B ){  11       Return A. P < B. P;  12  }  13   Int  Main (){  14       //  Freopen ("in.txt", "r", stdin );  15       Int  Cases;  16 Cin> Cases;  17       While (Cases -- ){  18          Int N, m; CIN> N> M;  19           For ( Int I = 0 ; I <m; I ++ )  20 Cin> rice [I]. P> Rice [I]. h;  21 Sort (rice, rice + M, mycomp );  22           Double Ans = 0 ;  23           For ( Int I = 0 ; I <m; I ++ ){  24               If (N> rice [I]. p * Rice [I]. h ){  25 N-= rice [I]. p * Rice [I]. h;  26 Ans + = Rice [I]. h;  27  }  28               Else   If (N <= rice [I]. p * Rice [I]. h ){  29 Ans + = N * 1.0 / Rice [I]. P;  30 Cout < Fixed <Setprecision ( 2 ) <Ans < '  \ N  ' ;  31                   Break  ;  32   }  33   34   }  35   }  36 }

Simulate and sort.

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.