POJ 2646 The Trip
来源:互联网 发布:linux火狐57乱码 编辑:程序博客网 时间:2024/04/27 23:12
POJ 2646 The Trip
题目链接:http://poj.org/problem?id=2646
题意:有n个学生的花费,计算使他们平摊花费所移动钱最少是多少。
注意:“the minimum amount of money that must change hands in order to equalize(within a cent) all the students' costs. ”
题目中最关键的一句,最少的钱——the minimum amount of money。精确到1美分——(within a cent);
AC代码:
#include<stdio.h>int main(){int n,i;double a[1100],sum,ave;double ans1,ans2;while(scanf("%d",&n)!=EOF,n){sum=0;for(i=0;i<n;i++){scanf("%lf",&a[i]);sum+=a[i];}ave=((int)((sum/n+0.005)*100))/100.0;ans1=ans2=0;for(i=0;i<n;i++){if(a[i]>ave)ans1+=a[i]-ave;elseans2+=ave-a[i];}printf("$%.2lf\n",ans1>ans2? ans2:ans1);}return 0;}
0 0
- POJ 2646 The Trip
- POJ-3287-The Trip, 2007
- Poj 3287 The Trip, 2007 (简单贪心)
- poj 3287 The Trip, 2007_贪心
- The trip
- The Trip
- The Trip
- HDU 1599 find the mincost route 、 poj 1734 Sightseeing trip
- POJ 1734 Sightseeing trip
- POJ 1934 Trip DP
- POJ 1734-Sightseeing trip
- poj 1934 Trip
- poj 3301 Texas Trip
- POJ 3301 Texas Trip
- POJ 3301 Texas Trip
- POJ 3301Texas Trip
- Texas Trip+POJ+三分
- poj 1934 Trip (LCS)
- js,jQuery 排序的实现,网页标签排序的实现,标签排序
- DLL(动态链接库)编程 (概论)
- [leetcode]LRU Cache (python)
- Sublime text 入门学习资源篇及其基本使用方法
- JDBC 常用函数实例说明
- POJ 2646 The Trip
- 可怕的阶乘
- Light OJ 1004
- 判断两台计算机IP地址是同一子网络 华为OJ训练平台---转载
- 用InstallAnywhere工具打包J2EE程序为.exe文件
- 取石子(一)
- spring学习之@SessionAttributes
- 求M的N次方的最后三位 转载
- hdu 1503:Advanced Fruits(动态规划+路径输出)