Pat a problem-1070. Mooncake (25)-Sort, flood problem

Source: Internet
Author: User

#include <iostream>#include<cstdio>#include<algorithm>#include<string.h>using namespacestd;/*3 0180 1007.5 7.2 4.5*/Const intmaxn= ++5;intAMOUNTS[MAXN];floatPRICE[MAXN];structcake{floatAmounts;//Note that this must be set to a floating point type, if the int is not a regular    floatPrice ; floatUnitprice=0; BOOL operator< (ConstCake tmp)Const{        returnUnitprice>Tmp.unitprice; }}CAKE[MAXN];intMain () {intn,d; scanf ("%d%d",&n,&d);  for(intI=0; i<n;i++) {scanf ("%f",&cake[i].amounts); }     for(intI=0; i<n;i++) {scanf ("%f",&Cake[i].price); Cake[i].unitprice=cake[i].price/cake[i].amounts; } sort (Cake,cake+N); floatans=0;  for(intI=0; i<n;i++){        if(d>=cake[i].amounts) {ans+=Cake[i].price; D-=cake[i].amounts; }        Else{ans+ = (d/cake[i].amounts) *Cake[i].price;  Break; }} printf ("%.2f", ans); return 0;}
View Code

Pat a problem-1070. Mooncake (25)-Sort, flood question

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.