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个首都城市,一个首都城市与每个城市都相连,求所有边的权值. 题解: ...
随机推荐
- 在ubuntu上搭建开发环境5---联想Y470安装 ubuntu,解决双显卡发热等问题
ubuntu14 没有解决显卡的问题的时候,会有这样的问题 1.耗电特别快.风扇狂转 2.鼠标键头显示有问题,乱闪,根本没法使用,容易卡住找不到鼠标箭头在哪里了:感觉图形界面显示也有问题,不稳定 解决 ...
- 【JAVA正则表达式综合练习】
一.治疗口吃. 将字符串“我我我我我我我..........我.......要要要要要..................要要要要...学习习习习.......习习习习习习习习编程程程程程程..... ...
- python多线程之Event(事件)
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from threading import Thread, Event import ...
- 浅析配置更快的Eclipse方法
很多人感觉自己的elipse启动比较慢,其实并不是因为装的插件太多或者是导入的项目有点大,而是因为参数的设置不合理导致的.可以在eclipse.ini里面添加-Xloggc:gc.log看看启动的日志 ...
- SOLR+LUCENE错误
java.lang.NoClassDefFoundError: org/apache/lucene/analysis/synonym/SynonymFilter 该错误发生在自定义SOLR服务器时,原 ...
- 使用nbrbutil工具來處理requested media id is in use, cannot process request
首先我發現一個Media已經過期很久,但是并不會覆蓋重用 使用bpexpdate手動過期,失敗,讓他deassigned也不行 使用bpimmedia查看上面的image也沒有 我嘗試手動去過期,返回 ...
- hdu 4007 暴力or线段树 ***
尼玛,INF不能定义太大,找标程对拍了好久 #include<cstdio> #include<iostream> #include<algorithm> #inc ...
- 重新开始刷dp,哈哈哈
转载于: http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2015年1月29日 从头开始
- 装饰模式/decorator模式/结构型模式
装饰模式Decorator 定义 为对象动态的增加新的功能,实现要求装饰对象和被装饰对象实现同一接口或抽象类,装饰对象持有被装饰对象的实例. java实现要点 定义一个接口或抽象类,作为被装饰者的抽象 ...
- 用C获得当前系统时间(转)
#include <stdio.h> #include <time.h> void main () { time_t rawtime; struct tm * timeinfo ...