Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求助:I got WA 3x#include<stdio.h> #include<stdlib.h> struct cow{ double position,pre,back; }; int cmp(const void *x, const void *y) { return (*(cow*)x).position - (*(cow*)y).position; } void main() { int n; double sum=0; scanf("%d",&n); cow *cc=new cow[n]; for(int i=0;i<n;i++){ scanf("%lf",&cc[i].position); cc[i].pre=cc[i].back=0.0; } qsort(cc,n,sizeof(cow),cmp); for(i=1;i<n;i++)cc[0].back+=cc[i].position-cc[0].position; sum=cc[0].back; for(i=1;i<n;i++){ cc[i].pre=cc[i-1].pre+i*(cc[i].position-cc[i-1].position); cc[i].back=cc[i-1].back-(n-i)*(cc[i].position-cc[i-1].position); sum+=cc[i].pre+cc[i].back; } printf("%.0lf\n",sum); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator