Ultraviolet A Problem 10137 the trip (travel)

Source: Internet
Author: User
Tags dot net
// The trip // PC/ultraviolet A IDs: 110103/10137, popularity: B, success rate: average level: 1 // verdict: accepted // submission date: 2011-04-09 // UV Run Time: 0.016 S // copyright (c) 2011, Qiu. Metaphysis # Yeah dot net // calculate the "average fee" first, that is, the total fee is calculated by the number of students. Because the difference between the payment and the number of students is less than 1 cent, therefore, you can // take the two digits after the decimal point into consideration during calculation. The number after the third digit is rounded to 9.666. For example, if the average value is 666 // 9.67, is used. Read positive integer n first, and then read N values in sequence. Add all expenses to get the average value. Based on the question // purpose requirement, the student can be divided into two groups, where the advance fee is higher than the average fee, A group is less than or equal to // average fee. Students with more advances should refund the money, and those with less advances should be charged. Take the least part according to the question. Here, // note the following data: 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.03, the average value of the data in this group is 0.01, but it is not a refund of $0.03 for the person who spent $0.02/, because as long as the satisfaction error is within 1 cent, therefore, you only need to refund the person who spent $0.03 USD $0.01 to meet the cost error of all people within 1 cent. This detail may be something that most people did not notice when submitting the answer to this question. //// Pay attention to the use of data types. In this question, because each student's expenditure does not exceed $100000, if it is represented by a single-precision floating point number, // It is defined according to the single-precision number, seven valid data records can be retained, but when the total fee of students exceeds $100000.00, the current precision will be lost. Therefore, dual-precision data is required, otherwise, the result is incorrect. # Include <iostream> using namespace STD; # define size 1000 double findchange (double * Money, int total) {double average = 0.0, changedown = 0.0, changeup = 0.0, change = 0.0; For (INT I = 0; I <total; I ++) Average + = money [I]; average/= total; average = (long) (Average * 100 + 0.5)/100.00; For (INT I = 0; I <total; I ++) {If (money [I]> average) changeup + = (money [I]-average); elsechangedown + = (average-money [I]);} If (changedown> 0 & changeup> 0) {If (changedown> changeup) change = changeup; elsechange = changedown;} else {If (changeup = 0 & changedown = 0) change = 0.0; else {If (changedown = 0) {for (INT I = 0; I <total; I ++) if (money [I]> average) change + = (money [I]-average-0.01);} else {for (INT I = 0; I <total; I ++) if (money [I] <average) Change + = (average-money [I]-0.01) ;}} return change ;}int main (INT AC, char * AV []) {double money [size], result = 0.0; int total; while (CIN> total, total) {for (INT I = 0; I <total; I ++) CIN> money [I]; Result = findchange (money, total); cout. precision (2); cout. SETF (IOs: Fixed | IOs: showpoint); cout <"$" <result <Endl;} 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.