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:太奇怪了 输入数据也需要long long ???

Posted by JustForU at 2011-02-11 16:51:18 on Problem 2231
In Reply To:太奇怪了 输入数据也需要long long ??? Posted by:dxtkdxtk at 2011-01-21 23:48:56
我也是啊。。。
我排序以后O(n)的递推
改成long long x[10005];就AC了,不解。。。

我看discuss里有的程序不用这样啊。。。

------------------------
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

long long f[10005];
int x[10005];  

long long solve(int n){
	if(n==1)return 0;
	if(n==2)return 2*(x[2]-x[1]);
	int i;
	f[2]=x[2]-x[1];
	f[3]=x[3]-x[1]+x[3]-x[2]+f[2];
	for(i=4;i<=n;i++)
	{
		f[i]=(i-1)*(x[i]-x[i-1])+2*f[i-1]-f[i-2];
	}
	
	return 2*f[n];
}

int main(){
	int n;
	int i;
//	freopen("aaa.txt","r",stdin);
	while(scanf("%d",&n)!=EOF){
		for(i=1;i<=n;i++)scanf("%d",&x[i]);
		sort(x+1,x+1+n);
		cout<<solve(n)<<endl;
	}
}

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