Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我也不知道为什么,凑了个程序就AC了,对精度的问题我也没有很好理解

Posted by zerocool_08 at 2005-10-14 10:16:42 on Problem 2646
In Reply To:那你就帮忙指出来吧!我也想学习一下 Posted by:zerocool_08 at 2005-10-14 10:05:02
#include "stdio.h"
int main(void)
{
    double   sum,ave,a[1010],s1,s2;
    int     n,i,temp;
    while(scanf("%d",&n)==1&&n)
    {
        sum=0;
        for(i=0;i<n;i++)
           scanf("%lf",&a[i]),sum+=a[i];
        ave=sum/n;
        temp=(int)(ave*100+0.5);
        ave=temp/100.0;
        for(i=0,s1=0,s2=0;i<n;i++)
        {
            if(a[i]>ave)
               s1+=a[i]-ave;
            else
                s2+=ave-a[i];
        }
        sum=s1<s2? s1:s2;           
        printf("$%.2lf\n",sum);
    }
}        


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator