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

Re:公式我找到了(程序也AC了)~可是意思还是不太理解,能提点一下在哪找到的公式,或者思路是怎样的吗?

Posted by stfairy at 2007-11-12 23:08:38 on Problem 2231
In Reply To:Re:公式我找到了(程序也AC了)~可是意思还是不太理解,能提点一下在哪找到的公式,或者思路是怎样的吗? Posted by:ray58750034 at 2005-03-05 23:28:08
    qsort(a, n, sizeof(long long), compare);
    for(i=0;i<n-1;i++)
        vol+=(a[i+1]-a[i])*(i+1)*(n-i-1);
    cout<<vol*2;

    从左向右传和从右向左传是对称的, 所以vol×2;
    考虑中间的一小段距离,因为左边的牛的声音
    要传到右边的牛的耳朵里,必然要经过一些相邻的小段距离,
    这些距离是要被重复计算的,而某一段左边有i+1头牛,
    右边有n-i-1头牛,所以是(i+1)×(n-i-1)

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