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个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
随机推荐
- TCP 四次握手
TCP协议中的三次握手和四次挥手(图解) http://blog.csdn.net/whuslei/article/details/6667471/
- linux cpuInfo
转自:http://blog.csdn.net/lgstudyvc/article/details/7889364 /proc/cpuinfo文件分析 在Linux系统中,提供了proc文件系统显 ...
- SQL Server 2014 BI新特性(三)Power Query和Power Map功能预览
Power Query和Power Map是微软前不久在WPC上发布的Power BI中新的针对Excel的功能.借助这两样功能,自助式BI将更方便你发现和处理数据并且丰富数据的可视化功能. Powe ...
- httpclient 4.5 get请求
还是官网靠谱啊 package com.test.httpclient.getpost; import java.io.IOException; import java.util.ArrayList; ...
- Installing MySQL Server on CentOS
MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...
- Web分布式架构演变过程
1 单台服务器 2 应用服务器与数据库服务器 文件服务器分开 3 数据库 缓存 读写分离 实时写 非实时写 4 应用服务器集群 需要再配一台”负载均衡调度器“,nginx 5 数据库拆封 主库 ...
- Android屏幕适配全攻略(最权威的官方适配指导) (转)
招聘信息: Cocos2d-X 前端主程 [新浪微博]手机客户端iOS研发工程师 20k-40k iOS 开发工程师 iOS高级开发工程师(中国排名第一的企业级移动互联网云计算公司 和创科技 红圈营销 ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- HDU 5875 Function st + 二分
Function Problem Description The shorter, the simpler. With this problem, you should be convinced ...
- Loadrunner的自定义监控器
Loadrunner的自定义监控器 可以使用lr_user_data_point()来实现自定义监控,下面是一个小例子: double showsomething(); Action(){ doubl ...