Original question:
A number of students is members of a club, travels annually to exotic locations. Their destinations in the past has included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they is planning a trip to Eindhoven.
The group agrees in advance to share expenses equally, but it isn't practical to has them share every expense as it OCCU Rs. So individuals in the group pay for particular things, like meals, hotels, taxi rides, plane tickets, etc. After the trips, each student ' s expenses was tallied and money was exchanged so, the net cost to each of the same, to WI Thin one cent. In the past, this money exchange has been tedious and time consuming. Your job is to compute, from a list of expenses, the minimum amount of
Money, must change hands in order to equalize (within a cent) all the students ' costs.
Input
Standard input would contain the information for several trips. The information consists of a line containing a positive integer, n, and the number of students on the trip, fol Lowed by n lines of input, each containing the amount, in dollars and cents, spent by a student. There is no more than-students and no student spent more than $10,000.00. A single line containing 0 follows the information.
Output
For each trip, output a line stating the total amount of money, in dollars and cents, that must being exchanged to equalize T He students ' costs.
Sample Input
3
10.00
20.00
30.00
4
15.00
15.01
3.00
3.01
0
Sample Output
$10.00
$11.99
English:
There are n students out to play, spend a little money, now to be equally. If there is no way to perfect the spread, then the maximum can be 0.01 yuan. Now ask you, if before each person to dig a part of the money, dig less to give more of those people how much money. What the minimum can be.
#include <bits/stdc++.h>
using namespace std;
Double a[1001];
int n;
int main ()
{
Ios::sync_with_stdio (false);
while (Cin>>n,n)
{
double tmp=0,ans1=0,ans2=0;
memset (A,0,sizeof (a));
for (int i=1;i<=n;i++)
{
cin>>a[i];
Tmp+=a[i];
}
Tmp/=n;
Tmp=round (tmp*100.0)/100.0;
for (int i=1;i<=n;i++)
{
if (a[i]>tmp)
ans1+= (a[i]-tmp);
else
ans2+= (tmp-a[i]);
}
Cout<<fixed<<setprecision (2) << ' $ ' <<min (ANS1,ANS2) <<endl;
}
return 0;
}
Answer:
Originally is to do other questions, the result staggered the problem number, this problem did.
Averages are calculated first, and two decimal places are reserved.
And then calculate the sum of the difference between the average person less than the average, minus each person, and the sum of the difference between the average and each person minus the mean. Compare which small can