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. 关于plsql连接oracle数据库session失效时间设置

    http://bbs.csdn.net/topics/350152441 http://www.linuxidc.com/Linux/2015-09/123286.htm

  2. 12.享元模式(Flyweight Pattern)

    using System; using System.Collections; namespace ConsoleApplication5 { class Program { /// <summ ...

  3. 【Javascript】IE8兼容 背景图片与a标签的onclick事件

    先说几句牢骚话. 虽然IE8比之IE6.7有很大的进步,但是在执行效率.兼容性上仍然有很多问题.被广大开发者喜爱的平台才是好平台. 可惜多亏当年盗版XP打开中国的计算机市场,IE作为一款捆绑软件仍然在 ...

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

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

  5. jQuery easyUI datagrid 增加求和统计行 分类: JavaScript 2015-01-14 17:46 2178人阅读 评论(0) 收藏

    在datagrid的onLoadSuccess事件增加代码处理. <style type="text/css"> .subtotal { font-weight: bo ...

  6. less 入门1

    less 入门1 less.html <!DOCTYPE html> <html lang="zh-cn"> <head > <meta ...

  7. 2-05使用SQL语句创建数据库2

    使用SQL语句创建多个数据文件和日志文件: USE master--指向当前使用的数据库 GO--批处理的标志 CREATE DATABASE E_Market--创建E_market数据库 ON P ...

  8. 跟着鸟哥学Linux系列笔记0-如何解决问题

    跟着鸟哥学Linux系列笔记0-扫盲之概念 在发生问题怎么处理: 1.  在自己的主机.网络数据库上查询How-To或FAQ -Linux 自身的文件数据: /usr/share/doc -CLDP中 ...

  9. 把浏览器的私有模式添加到VS中

    题记:在用VS进行Web开发的时候,常常希望VS的调试不会对浏览器造成固定的影响,那么使用浏览器的私有模式来启动就很有必要. 前几天SCOTT HANSELMAN分享了一个开发Web应用程序的小技巧, ...

  10. xcode6 下 ios simulator 有 Home 键么?

    4s之前 ,现在,只能用command+shift+h来代替