P4995 跳跳题解
作者:互联网
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 310;
int a[N];
int n;
LL res;
int h, t, cnt;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
//策略:从最低直接跳到最高,然后跳到次低,跳到次高...
t = n;
//双指针开始
while (h < t) {
cnt++;
res += pow(a[h] - a[t], 2);
if (cnt % 2 > 0)h++;
else t--;
}
//输出大吉
cout << res << endl;
return 0;
}
标签:P4995,跳跳,题解,LL,cnt,long,int,res,++ 来源: https://www.cnblogs.com/littlehb/p/15037971.html