10分求助,悬赏一个赞!
查看原帖
10分求助,悬赏一个赞!
1013149
fuyanchun楼主2023/8/3 12:02

Code:

#include <bits/stdc++.h>
using namespace std;
int n,h[500]={0},ans,point=1;
int main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> h[i];
    sort(h,h+n);
    int l=0,r=n;
    while(r>l)
    { 
        ans+=pow(h[r]-h[l],2);
        l++;
        ans+=pow(h[l]-h[r],2);
        r--;
    }
   cout << ans;
   return 0;
}
2023/8/3 12:02
加载中...