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 |
Re:原来溢出后结果是WAIn Reply To:原来溢出后结果是WA Posted by:awper361 at 2008-06-28 22:24:08 恩,将long改成long long 就可以AC了 #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N; vector<long long> location; while(cin>>N) { location.clear(); int i; long long loc; long long sum = 0,sum2 = 0,sum1=0,res = 0; for(i = 0;i!=N;++i) { cin>>loc; location.push_back(loc); sum+= loc; } sort(location.begin(),location.end()); sum2 = sum; for(i = 0;i!=N;++i) { sum2 -= location[i]; res += (sum2 - N*location[i] + 2*i*location[i] + location[i]- sum1); sum1 += location[i]; } cout<<res<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator