The Trip
来源:互联网 发布:ccproxy 类似软件 编辑:程序博客网 时间:2024/04/28 08:33
Problem A: The Trip
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.
The 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.The 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
310.0020.0030.00415.0015.013.003.010
Output for Sample Input
$10.00$11.99
#include <stdio.h>#define num 1005double s[num];int main(){ int n, t, i; while (scanf("%d", &n) == 1 && n) { double sum = 0, resultH = 0, resultL = 0; for (i = 0; i < n; i++) { scanf("%lf", &s[i]); sum += s[i]; } sum /= n; for (i = 0; i < n; i++) if (s[i] < sum) { resultL += (int)((sum - s[i])*100) / 100.0; } else resultH += (int)((s[i] - sum)*100) / 100.0; printf("$%0.2lf\n", resultL < resultH ? resultH:resultL); } return 0;}
- The trip
- The Trip
- The Trip
- The first trip
- 10137 - The Trip
- UVa 10137 The Trip
- UVa 10137 The trip
- Uva 10137 - The Trip
- UVa 10137 - The Trip
- ZOJ 1847 The Trip
- 10137 - The Trip
- The Trip. 2007
- 11100 - The Trip, 2007
- UVA 10137 The Trip
- Uva 10137 the trip
- UVaOJ11100 - The Trip, 2007
- uva 10137 The trip
- uva 10137 The Trip
- jQuery设计思想
- Adobe Alchemy Hello world
- oracle 分析函数
- 实时渲染(第三版):第一章 简介
- 共享库函数调用原理
- The Trip
- Debug命令
- 分享一个实时动态修改测试网站字体的jQuery代码片断
- 初探异步 AsyncTask 扫描SD卡指定后缀
- 栈---算符优先算法
- 笔记本+win7下USB转串口驱动的安装
- 学习算法之路
- android中的
- 旅游路线 解题报告