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 |
求变态数据不知道哪里错了,总是WA #include<iostream> #include<algorithm> using namespace std; const long SEG=10000000; class Safe { public: Safe() { cin>>N; one=new long[N]; two=new long[N]; for(long i=0;i<N;i++) cin>>one[i]; std::sort(one, one+N); result=0; } double getresult() { caldistance(); return result; } ~Safe() { delete [] one; delete [] two; } private: void caldistance() { double tempresult = 0; for(long i=0; i<N-1; i++) two[i] = one[i+1]-one[i]; two[N-1]=SEG-one[N-1]+one[0]; long symetric, isymetric, numleft=0, numright=0; symetric = one[0] + SEG/2; while(one[numleft] < symetric && numleft < N) numleft++; numright = N - numleft +1; for(long i=1; i<numleft; i++) tempresult += one[i] - one[0]; for(long i=numleft; i<N; i++) tempresult += SEG - one[i] + one[0]; result = tempresult; for(long index=1; index<N; index++) { if(one[index]==one[index-1]) continue; isymetric = one[index-1] + SEG/2; symetric = one[index] + SEG/2; if(symetric <= SEG) { tempresult -= two[index-1] * (numleft - index); while(one[numleft] < symetric) { if(numleft >= N) { break; } tempresult = tempresult + (one[numleft]-one[index]) - (SEG - one[numleft] + one[index-1]); numleft++; } numright = N - numleft + index; tempresult += two[index-1] * numright; } else { symetric-=SEG; if(isymetric <=SEG) { tempresult -= two[index-1] * (numleft - index); while(true) { if(numleft >= N) { break; } tempresult = tempresult + (one[numleft]-one[index]) - (SEG - one[numleft] + one[index-1]); numleft++; } numleft=0; while(one[numleft] < symetric) { if(numleft >= N) { break; } tempresult = tempresult + (one[numleft]-one[index]) + (SEG + one[numleft] - one[index-1]); numleft++; } numright = index - numleft; tempresult += two[index-1] * numright; } else { if(numleft==N) numleft=0; tempresult -= two[index-1] * (numleft + N - index); while(one[numleft] < symetric) { if(numleft >= N) { break; } numleft++; tempresult = tempresult + (one[numleft]-one[index]) + (SEG + one[numleft] - one[index-1]); } numright = index - numleft; tempresult += two[index-1] * numright; } } if(tempresult < result) result = tempresult; } } long N; long* one; long* two; double result; }; int main() { Safe safe; printf("%.0lf\n",safe.getresult()); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator