1301. The Trip
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的更多相关文章
- 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 ...
- dp or 贪心 --- hdu : Road Trip
Road Trip Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 29 ...
- 【poj1041】 John's trip
http://poj.org/problem?id=1041 (题目链接) 题意 给出一张无向图,求字典序最小欧拉回路. Solution 这鬼畜的输入是什么心态啊mdzz,这里用vector储存边, ...
- 三分 --- POJ 3301 Texas Trip
Texas Trip Problem's Link: http://poj.org/problem?id=3301 Mean: 给定n(n <= 30)个点,求出包含这些点的面积最小的正方形 ...
- HDOJ 1301
9852303 2013-12-18 11:47:01 Accepted 1301 0MS 264K 1117 B C++ 泽泽 Jungle Roads Time Limit: 2000/1000 ...
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem C: The Trip(水题)
Problem C: The Trip Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 19 Solved: 3[Submit][Status][Web ...
- hdu 3018 Ant Trip 欧拉回路+并查集
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- URAL 1004 Sightseeing Trip(最小环)
Sightseeing Trip Time limit: 0.5 secondMemory limit: 64 MB There is a travel agency in Adelton town ...
- Codeforces Round #365 (Div. 2) Mishka and trip
Mishka and trip 题意: 有n个城市,第i个城市与第i+1个城市相连,他们边的权值等于i的美丽度*i+1的美丽度,有k个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
随机推荐
- Linux如何查看与/dev/input目录下的event对应的设备
1.查看当前的设备 dev/input/ 2.查看设备的名称 cat /proc/bus/input/devices
- Delphi中的函数指针判断是否为空
delphi函数指针 只有@@p才代表了函数指针本身的地址 assigned(p) 判断是否为空 或者用 @p=nil 来判断函数指针是不是为空 Delphi中的函数指针实际上就是指针,只是在使用 ...
- 一致性hash算法简介与代码实现
一.简介: 一致性hash算法提出了在动态变化的Cache环境中,判定哈希算法好坏的四个定义: 1.平衡性(Balance) 2.单调性(Monotonicity) 3.分散性(Spread) 4.负 ...
- phpcms 完美实现 导航栏当前栏目高亮
我们在用phpcms做网站的时候,经常碰到导航栏高亮功能,或者侧栏高亮,这个会涉及到几个问题: .栏目列表页子栏目高亮判断,如果当前页面为子栏目,他的顶级栏目如果在导航栏也要高亮. .内容页高亮,这个 ...
- C# jsonhelper
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Sc ...
- loj 1377 (bfs)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1377 思路:这道题只要处理好遇到"*"这种情况就可以搞定了.我们可 ...
- css把超出的部分显示为省略号的方法兼容火狐
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- 【框架】异步加载大量图片--ImageLoader
public abstract class BaseImageLoaderProvider { public abstract void loadImage(Context ctx, ImageLoa ...
- Loadrunner参数化连接oracle、mysql数据源报错及解决办法
Loadrunner参数化连接oracle.mysql数据源报错及解决办法 (本人系统是Win7 64, 两位小伙伴因为是默认安装lr,安装在 最终参数化的时候,出现连接字符串无法自动加载出来: 最 ...
- 关于main函数传参数的问题
argc是命令行总的参数个数 argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数 命令行后面跟的用户输入的参数,比如: int main(int ...