#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>

using namespace std;
/*
* A solution for "The Trip" problem.
* UVa ID: 10137
*/
#include <stdio.h>

int main (int argc, const char * argv[]) {
    /* number of students in the trip */
    long numOfStudents;
   
    /* the total sum of money spent */
    double total;
   
    /* the total amount of money to exchange in order to equalize */
    double exchange;
   
    /* the equalized trip amount to be payed by each student */
    double equalizedAmount;
   
    /* difference between the equalized amount and the amount spent */
    double diff;
   
    /* sum of all negative differences */
    double negativeSum;
   
    /* sum of all positive differences */
    double positiveSum;
   
    /* iterator */
    int i;
   
    while(scanf("%ld", &numOfStudents) != EOF) {
               
        /* 0, ends the program */
        if (!numOfStudents) {
            return 0;
        }
       
        /* keeps the amount of money spent by each student */
        double amountSpent[numOfStudents];     
       
        /* clean */
        total = 0;
        negativeSum = 0;
        positiveSum = 0;
               
        for (i = 0; i < numOfStudents; i++) {
            scanf("%lf\n", &amountSpent[i]);
            total += amountSpent[i];
        }
               
        equalizedAmount = total / numOfStudents;
       
        for (i = 0; i < numOfStudents; i++) {
            /* to ensure 0.01 precision */
            diff = (double) (long) ((amountSpent[i] - equalizedAmount) * 100.0) / 100.0;
           
            if (diff < 0) {
                negativeSum += diff;
            } else {
                positiveSum += diff;
            }
        }

        /* when the total amount is even, these sums do not differ. otherwise, they differ in one cent */
        exchange = (-negativeSum > positiveSum) ? -negativeSum : positiveSum;
                       
        /* output result */
        printf("$%.2lf\n", exchange);
    }

    return 0;
}

The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1的更多相关文章

  1. Minesweeper PC/UVa IDs: 110102/10189, Popularity: A,Success rate: high Level: 1

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...

  2. PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版

    , '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...

  3. 挑战编程PC/UVa Stern-Brocot代数系统

    /* Stern-Brocot代数系统 Stern-Brocot树是一种生成所有非负的最简分数m/n的美妙方式. 其基本方式是从(0/1, 1/0)这两个分数开始, 根据需要反复执行如下操作: 在相邻 ...

  4. PC/UVa 题号: 110105/10267 Graphical Editor (图形化编辑器)题解

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...

  5. PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解

    #include <string> #include <iostream> #include <cstring> #include <algorithm> ...

  6. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  7. UVa 122 (二叉树的层次遍历) Trees on the level

    题意: 输入一颗二叉树,按照(左右左右, 节点的值)的格式.然后从上到下从左到右依次输出各个节点的值,如果一个节点没有赋值或者多次赋值,则输出“not complete” 一.指针方式实现二叉树 首先 ...

  8. Uva 122 树的层次遍历 Trees on the level lrj白书 p149

    是否可以把树上结点的编号,然后把二叉树存储在数组中呢?很遗憾如果结点在一条链上,那将是2^256个结点 所以需要采用动态结构 首先要读取结点,建立二叉树addnode()+read_input()承担 ...

  9. uva 704

    自己之前的不见了.. 这题是双向广搜即可过.. // Colour Hash (色彩缤纷游戏) // PC/UVa IDs: 110807/704, Popularity: B, Success ra ...

随机推荐

  1. MPI编程的常用接口速查

    获取当前时间 在插入MPI提供的头文件后,可以获得获取时间的函数. double MPI_Wtime(void) 取得当前时间, 计时的精度由 double MPI_Wtick(void) 取得作为对 ...

  2. 【轻院热身赛】级数求和、进制转换、candy

    [题目链接:级数求和] Problem A: 级数求和 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 409  Solved: 240 SubmitSt ...

  3. TCP/IP详解学习笔记(12)-TCP的超时与重传

    超时重传是TCP协议保证数据可靠性的另一个重要机制,其原理是在发送某一个数据以后就开启一个计时器,在一定时间内如果没有得到发送的数据报的ACK报文,那么就重新发送数据,直到发送成功为止. 1.超时 超 ...

  4. HDU 1387 Team Queue

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. poj 4052(ac自动机)

    题意:自己百度吧!! 分析:就是通过它的fail指针来找出它的子串就行了,这题其实不难的.这好像还是金华邀请赛的题哦! 代码实现: #include<cstdio> #include< ...

  6. Linux基本命令(5)管理使用者和设立权限的命令

    管理使用者和设立权限的命令 命令 说明 命令 说明 chmod 用来改变权限 useradd 用来增加用户 su 用来修改用户     5.1 chmod命令 chmod命令用来改变许可权限.读取.写 ...

  7. VC++6.0连接Access数据库

    建立一个连接数据库的类: 1.头文件:ADOConn.h #import "C:\Program Files\Common Files\System\ado\msado15.dll" ...

  8. MFC字体与文本输出

    字体 成员函数 1.CFont( ); 构造一个CFont对象.此对象在使用之前应该先使用CreateFont.CreateFontIndirect.CreatePointFont或CreatePoi ...

  9. codeforces 704B - Ant Man 贪心

    codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...

  10. java 最佳且开源的反编译工具

    1.jad:2.jode 很多gui的反编译工具(decafe,DJ,cavaJ)差不多都是基于jad和jode的.