HDU 2187 Mourning 512 Wenchuan earthquake--The old man is really hungry.

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2187

Questions Jane asked:

Problem Solving Ideas:

Given the total amount of money and the kind of altogether

1. To the given rice, according to the price of ascending, that is, the cheapest rice to the top

2. If the current rice unit Price * Quantity > Total amount, then can buy sum+= total money/Unit Price

Otherwise sum+= the total weight of the current rice, while the total amount of money = Rice Unit Price * Quantity.

3. Output sum, note the format.

AC Code:

#include <stdio.h> #include <stdlib.h>struct n{    int dj,zl;}; int cmp (const void *a,const void *b) {    n *a1= (n *) A;    n *b1= (n *) b;    return A1->DJ-B1->DJ;} int main (void) {    int c,tp,i;    Double mo,sum;    struct N n[1010];    scanf ("%d", &c);    while (c--)    {        sum=0;        scanf ("%lf%d", &MO,&TP);        for (i=0; i<tp; i++)        {            scanf ("%d%d", &n[i].dj,&n[i].zl);        }        Qsort (N,tp,sizeof (n[0]), CMP);        for (i=0; i<tp; i++)        {            if ((N[i].dj*n[i].zl) >=mo)            {                sum+=mo/(N[I].DJ);                break;            }            else            {                mo-= (N[I].DJ*N[I].ZL);                Sum+=n[i].zl;            }        }        printf ("%.2f\n", sum);    }    return 0;}

  

HDU 2187 Mourning 512 Wenchuan earthquake--The old man is really hungry.

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.