The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1
#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的更多相关文章
- Minesweeper PC/UVa IDs: 110102/10189, Popularity: A,Success rate: high Level: 1
#include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...
- PC/UVa 题号: 110106/10033 Interpreter (解释器)题解 c语言版
, '\n'); #include<cstdio> #include<iostream> #include<string> #include<algorith ...
- 挑战编程PC/UVa Stern-Brocot代数系统
/* Stern-Brocot代数系统 Stern-Brocot树是一种生成所有非负的最简分数m/n的美妙方式. 其基本方式是从(0/1, 1/0)这两个分数开始, 根据需要反复执行如下操作: 在相邻 ...
- PC/UVa 题号: 110105/10267 Graphical Editor (图形化编辑器)题解
#include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...
- PC/UVa 题号: 110104/706 LC-Display (液晶显示屏)题解
#include <string> #include <iostream> #include <cstring> #include <algorithm> ...
- 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 ...
- UVa 122 (二叉树的层次遍历) Trees on the level
题意: 输入一颗二叉树,按照(左右左右, 节点的值)的格式.然后从上到下从左到右依次输出各个节点的值,如果一个节点没有赋值或者多次赋值,则输出“not complete” 一.指针方式实现二叉树 首先 ...
- Uva 122 树的层次遍历 Trees on the level lrj白书 p149
是否可以把树上结点的编号,然后把二叉树存储在数组中呢?很遗憾如果结点在一条链上,那将是2^256个结点 所以需要采用动态结构 首先要读取结点,建立二叉树addnode()+read_input()承担 ...
- uva 704
自己之前的不见了.. 这题是双向广搜即可过.. // Colour Hash (色彩缤纷游戏) // PC/UVa IDs: 110807/704, Popularity: B, Success ra ...
随机推荐
- LeetCode Swap Nodes in Pairs 交换结点对(单链表)
题意:给一个单链表,将其每两个结点交换,只改尾指针,不改元素值. 思路:迭代法和递归法都容易写,就写个递归的了. 4ms /** * Definition for singly-linked list ...
- hdu 4435 charge-station
// 题意 从1出发逛完N个点回到出发点 要在这N个点选择性建设加油站 车每次加满油最多可以行使D米// 然后最少要花多少钱才能达到上述要求// 注意到 第i个城市的花费是 2^(i-1) 所以 我就 ...
- 【转】This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
原文网址:http://1982106a.blog.163.com/blog/static/8436495620149239361692/ 预览layout.xml文件时提示: This versio ...
- Oracle日常维护脚本
1.正常停库流程 ps -ef|grep LOCAL=NO|cut -c 9-15|xargs kill -9 shutdown immediate; 2.备份数据库 bac ...
- @section Right
布局页 _BaseLayout.cshtml @RenderSection("Right", true) 视图页 Index.cshtml @{ Layout = "~/ ...
- 锋利的jQuery读书笔记---jQuery中操作DOM
一般来说,DOM的操作分为3个方面,即DOM Core.HTML-DOM和CSS-DOM jQuery中的DOM操作主要包括以下种类: 查找节点 查找元素节点 查找属性节点 创建节点 创建元素节点 创 ...
- cgroup的测试数据
[root@xxxx /cgroup/memory/rule3021]#cat memory.limit_in_bytes503316480 480M [root@xxxx /cgroup/mem ...
- JMeter使用jar进行压力测试
最近需要对改造的redis缓存接口做压力测试,使用了开源压力测试工具JMeter,分享一下自己的使用经验,希望能对需要进行压力测试的开发同学有所帮助. JMeter介绍 JMeter是Apache软件 ...
- SQL对字符串进行排序
假设字符串中只由'A'.'B'.'C'.'D'组成,且长度为7.并设函数REPLICATE(<字符串>,<n>)可以创建一个<字符串>的n个副本的字符串,另外还有R ...
- oc_转_类的数组的实现和操作
OC的数组对象的基本方法的使用:因为OC的数组中存储的为对象类型,所以我们可以新建一个Person类,通过Person生成对象进行操作. 其中Person.h中的代码为: 01.#import&l ...