#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. OOP——UML六种关系

    UML定义的关系主要有:泛化.实现.依赖.关联.聚合.组合,这六种关系紧密程度依次加强,分别看一下 泛化 概念:泛化是一种一般与特殊.一般与具体之间关系的描述,具体描述建立在一般描述的基础之上,并对其 ...

  2. POJ 1094 Sorting It All Out

    题意:给出m对关于n个字母的小于关系,输出通过这些关系能得到的结论,如果可以排序就输出至少知道第几个关系时就可以知道顺序,从小到大输出顺序:如果产生歧义就输出在第几个关系时出现歧义,如果不能得出准确的 ...

  3. 对LR analysis的平均事务响应时间和summary中时间值不同的解释

    最近在做性能测试对LR结果分析时,又碰到了关于summary里与平均事务响应时间中各交易的响应时间值不同的问题.在此做个记录. 若交易中设置了思考时间,分析时需要注意查看是否过滤思考时间. 设置是否包 ...

  4. 一行命令实现Android自动关机

    前几天晚上失眠,实在睡不着觉,于是想用Nexus7听一听小野丽莎的歌,在安静祥和之中睡去(怎么感觉有点...)但是不能让平板总是这么循环播放吧(屋里吐槽Google Play Music),所以在平板 ...

  5. mybatis系列-07-输出映射

    7.1     resultType 使用resultType进行输出映射,只有查询出来的列名和pojo中的属性名一致,该列才可以映射成功. 如果查询出来的列名和pojo中的属性名全部不一致,没有创建 ...

  6. Linux下用Intel编译器编译安装NetCDF-Fortan库(4.2以后版本)

    本来这个问题真的没必要写的,可是真的困扰我太久%>_<%,决定还是记录一下. 首先,最权威清晰的安装文档还是官方的: Building the NetCDF-4.2 and later F ...

  7. Spark视频 王家林 Spark公开课大讲坛第二期: Spark的Shark和SparkSQL

    王家林 Spark公开课大讲坛第一期:Spark把云计算大数据速度提高100倍以上 http://edu.51cto.com/lesson/id-30816.html Spark实战高手之路 系列书籍 ...

  8. 关于OpenCV做图像处理内存释放的一些问题

    转载:http://blog.sina.com.cn/s/blog_67a7426a0101czyr.html 工程运行,发现内存持续增长,到一定的时候就发生了内存泄漏. 内存泄露的定义 内存泄露是说 ...

  9. Spark SQL概念学习系列之Spark SQL 架构分析(四)

    Spark SQL 与传统 DBMS 的查询优化器 + 执行器的架构较为类似,只不过其执行器是在分布式环境中实现,并采用的 Spark 作为执行引擎. Spark SQL 的查询优化是Catalyst ...

  10. 最大连续子数组问题-homework-01

    1)先写我的 github 的介绍: github 的域名:http://www.github.com/zhuifeng1022 登入 github 大概是下面的视图: 按照助教的方法:我已经建好了代 ...