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:原来溢出后结果是WA

Posted by ChouMing at 2008-09-14 12:03:46 on Problem 2231
In 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:
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