【Codeforces 1106C】Lunar New Year and Number Division

【链接】 我是链接,点我呀:)
【题意】

题意

【题解】

看了下样例解释就懂了。。。 每次选择最大最小的两个组合 然后加起来。。

【代码】

import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;


public class Main {
		
	static int n;
	static int a[];
	
	static long sqr(long x) {
		return x*x;
	}
	
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		a = new int[n+10];
		for (int i = 1;i <= n;i++) a[i] = in.nextInt();
		Arrays.sort(a, 1,n+1);
		int l = 1,r = n;
		long ans = 0;
		while (l<=r) {
			ans = ans + sqr(a[l]+a[r]);
			l++;r--;
		}
		System.out.println(ans);
	}

}
原文地址:https://www.cnblogs.com/AWCXV/p/10351456.html