A number of students are members of a club that travels annually to exotic locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, and Atlanta. This spring they are planning a trip to Eindhoven.

The group agrees in advance to share expenses equally, but it is not practical to have them share every expense as it occurs. So individuals in the group pay for particular things, like meals, hotels, taxi rides, plane tickets, etc. After the trip, each student's expenses are tallied and money is exchanged so that the net cost to each is the same, to within 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 that must change hands in order to equalize (within a cent) all the students' costs.

Input

Standard input will contain the information for several trips. The information for each trip consists of a line containing a positive integer, n, the number of students on the trip, followed by n lines of input, each containing the amount, in dollars and cents, spent by a student. There are no more than 1000 students and no student spent more than $10,000.00. A single line containing 0 follows the information for the last trip.

Output

For each trip, output a line stating the total amount of money, in dollars and cents, that must be exchanged to equalize the 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

Source: Waterloo
Local Contest Jan. 31, 1999

几点注意:

1、

2、

3、

4、

 /*
#include <stdio.h>
#include <string.h> float cost[100];
int cost100[100]; void sort(int num); int main(void)
{
int num,i,sum=0;
int avg,last;
int change_sum=0;
double change; scanf("%d",&num);
while(num != 0){
for(i=0;i<num;i++){
scanf("%f",&cost[i]);
cost100[i] = 100*cost[i] + 0.5;
sum += cost100[i];
}
avg = sum/num;
last = sum%num;
sort(num);
for(i=0;i<num;i++){
if(i<last)
cost100[i] = cost100[i] - avg - 1;
else
cost100[i] = cost100[i] - avg;
if(cost100[i] > 0)
change_sum += cost100[i];
} change = ((double)change_sum)/100;
printf("$%.2f\n",change); memset(cost,0,num*sizeof(float));
memset(cost100,0,num*sizeof(int)); sum = 0;
change_sum = 0; scanf("%d",&num);
} //system("PAUSE");
return 0;
}
void sort(int num)
{
int i,j;
for(i=0;i<num;i++){
for(j=0;j<num;j++){
if(cost100[j]<cost100[j+1]){
int temp = cost100[j];
cost100[j] = cost100[j+1];
cost100[j+1] = temp;
}
}
} }
*/ #include <stdio.h>
#define num 1005
double s[num];
int main()
{
int n, t, i;
while (scanf("%d", &n) == && n)
{
double sum = , resultH = , resultL = ;
for (i = ; i < n; i++)
{
scanf("%lf", &s[i]);
sum += s[i];
}
sum /= n; for (i = ; i < n; i++)
if (s[i] < sum)
{
resultL += (int)((sum - s[i])*) / 100.0;
}
else
resultH += (int)((s[i] - sum)*) / 100.0;
printf("$%0.2lf\n", resultL < resultH ? resultH:resultL);
}
return ;
}

1301. The Trip的更多相关文章

  1. Lesson 4 An existing trip

    Text I have just received a letter from my brother,Tim. He is in Australia. He has been there for si ...

  2. dp or 贪心 --- hdu : Road Trip

    Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29 ...

  3. 【poj1041】 John's trip

    http://poj.org/problem?id=1041 (题目链接) 题意 给出一张无向图,求字典序最小欧拉回路. Solution 这鬼畜的输入是什么心态啊mdzz,这里用vector储存边, ...

  4. 三分 --- POJ 3301 Texas Trip

    Texas Trip Problem's Link:   http://poj.org/problem?id=3301 Mean: 给定n(n <= 30)个点,求出包含这些点的面积最小的正方形 ...

  5. HDOJ 1301

    9852303 2013-12-18 11:47:01 Accepted 1301 0MS 264K 1117 B C++ 泽泽 Jungle Roads Time Limit: 2000/1000 ...

  6. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem C: The Trip(水题)

    Problem C: The Trip Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 19  Solved: 3[Submit][Status][Web ...

  7. hdu 3018 Ant Trip 欧拉回路+并查集

    Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  8. URAL 1004 Sightseeing Trip(最小环)

    Sightseeing Trip Time limit: 0.5 secondMemory limit: 64 MB There is a travel agency in Adelton town ...

  9. Codeforces Round #365 (Div. 2) Mishka and trip

    Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...

随机推荐

  1. HTML5学习之拖放(十)

    l元素可以用于拖拽必须设置draggable="true"属性,img和a标签除外,她们两个默认就可以被拖拽 想做拖拽处理,就需要在Dom元素上监听拖放的事件:dragstart, ...

  2. Shell编程基础教程3--Shell输入与输出

    3.Shell输入与输出    3.1.echo        echo命令可以显示文本行或变量,或者把字符串输出到文件        echo [option] string             ...

  3. 【转载】 Python 调整屏幕分辨率

    转载来自: http://www.cnblogs.com/fatterbetter/p/4115423.html 需要用windows的api,ChangeDisplaySettings 实现代码如下 ...

  4. 【翻译二十三】java-并发程序之随机数和参考资料与问题(本系列完)

    Concurrent Random Numbers In JDK 7, java.util.concurrent includes a convenience class, ThreadLocalRa ...

  5. 【JAVA IO流之字符流】

    一.概述. java对数据的操作是通过流的方式.java用于操作流的对象都在IO包中.流按照操作数据不同分为两种,字节流和字符流.流按照流向分为输入流,输出流. 输入输出的“入”和“出”是相当于内存来 ...

  6. wp8 入门到精通 测量代码执行时间

    Stopwatch time = new Stopwatch(); byte[] target = new byte[size]; for (int j = 0; j < size; j++) ...

  7. 如何更快的删除String中的空格[未完]

      背景:此文章主要源于网址[1]所描述的,文中大部分方法亦是[1]中实现的. 下面介绍集中删除空格的方法: 方法1:按空格分割后再拼接 /// <summary> /// 按空格分割后拼 ...

  8. 基于socket、多线程的客户端服务器端聊天程序

    服务器端: using System; using System.Windows.Forms; using System.Net.Sockets; using System.Net;//IPAddre ...

  9. 程序员最喜爱的12个Android应用开发框架二(转)

    在上一篇程序员最喜爱的12个Android应用开发框架(一)中,我们为大家介绍了前6个Android应用开发框架,主要包括了 Xamarin.Phonegap.Corona SDK等.接下来,小编将继 ...

  10. loj 1379(最短路变形)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27087 思路:题目的意思是求S->T的所有路径中花费总和小于 ...