uva 10137 The trip

/*
The trip
注意特殊数据的处理,误差不超过0.01即可。
*/#include<iostream>
#include<cstdio>
using namespace std;
double a[1005];
int main()
{
   // freopen("./pcio/110103.inp","r",stdin);
    int n,i;
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        double sum=0.00,sum1=0.00,sum2=0.00;
        int j=0,k=0;
        for(i=0; i<n; i++)
        {
            scanf("%lf",a+i);
            sum+=a[i];
        }
       double avg=sum/n;
       avg = (long) (avg * 100 + 0.5) / 100.00;
       for(i=0; i<n; i++)
        {
            if(a[i]>avg)
               sum1+=a[i]-avg;
            else
               sum2+=avg-a[i];
        }
       cout.precision(2);
       cout.setf(ios::fixed | ios::showpoint);
        if(sum1>0 && sum2>0)
        {
            if(sum1>sum2)
            cout<<'$'<<sum2<<endl;
        else
            cout<<'$'<<sum1<<endl;
        }
        else
        {
            if(sum1==0 && sum2==0)
                cout<<'$'<<0.0<<endl;
            else if(sum1==0)
            {
                for(i=0;i<n;i++)
                    if(a[i]>avg)
                    sum1+=(a[i]-avg-0.01);
                cout<<'$'<<sum1<<endl;
            }
            else if(sum2==0)
            {
                for(i=0;i<n;i++)
                    if(a[i]<avg)
                    sum2+=(avg-a[i]-0.01);
                cout<<'$'<<sum2<<endl;
            }
        }
    }
    return 0;
}
时间: 2024-09-29 04:50:32

uva 10137 The trip的相关文章

UVa 10137 The Trip:小数四舍五入&amp;amp;需要注意的地方

10137 - The Trip Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1078 A number of students are members of a club that travels annually to exotic locations

UVa 11100 The Trip, 2007:贪心&amp;amp;一举两得的输出技巧

11100 - The Trip, 2007 Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2041 A number of students are members of a club that travels annually to exotic lo

uva 11100 - The Trip, 2007

点击打开链接uva 11100 题目意思: 给定n个包,现在每一个包的形状相同,但是大小不同.现在规定小号的包可以包含在大号里面.例如 4-3-2-1,现在给我们n个包,要我们求出最后需要的包是几个,还有尽量满足每一个最后包之间包含的小包的个数相同 解题思路: 1:思路:贪心 2:分析如下:       1首先我们知道相同大小的包是不能够包含在同一个大包里面的,所以最后需要的大包的个数就是原来序列中相同型号包的最大值           2 知道了最后需要的包的个数,那么就可以根据总的包个数n求

UVa 11100:The Trip, 2007

[链接] http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=2041 [原题] A number of students are members of a club that travels annually to exotic locations. Their destinations in the past

算法:uva 1484 Alice and Bob&#039;s Trip (树形dp)

题意 给一棵n个结点的树,结点编号为0~n-1,顶点是0 每条边都有一个权值. Alice和Bob初始位 置在顶点,要往下一直走到叶子结点. 第一次是由Bob选择走向哪个子结点,第二次轮到Alice,依次轮流 下去... 每走过一条边就会获得相应的权值,Bob希望所走的路径总权值越大越好,而Alice希望越小越好 每次他们都会选择最优解. 最终总权值要在范围[L,R]之内. 问最终Bob希望的最大权值是多少? 思路 f(u, 0)表示第u点由Bob选时的最大值 f(u, 1)表示第u点由Alic

UVa 507:Jill Rides Again

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=448 类型: 最大连续和 原题: Jill likes to ride her bicycle, but since the pretty city of Greenhills where she lives has grown, Jill oft

UVa 757:Gone Fishing

[题目链接] http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=698 [原题]John is going on a fishing trip. He has h hours available ( ), and there are n lakes in the area ( ) all reachable a

UVa 10099:The Tourist Guide(Floyd, 最大生成树)

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1040 题目: Problem D The Tourist Guide Input: standard input Output: standard output Mr. G. works as a tourist guide. His current

UVa 324 Factorial Frequencies:高精度

324 - Factorial Frequencies Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=260 In an attempt to bolster her sagging palm-reading business, Madam Phoenix