样例全对,却全WA

P4995 跳跳!

@[mc_xiexie](/user/1095322) 好像你的思路错了,你这个不是最优解,最优解应该是每一次都是从最高点调到最低点
by lt1526679338 @ 2023-11-12 20:37:29


```c #include<bits/stdc++.h> using namespace std; long long int a[301],n,s; int main() { ios::sync_with_stdio(false); cin.tie(0); register int i,j; cin>>n; for(i=1; i<=n; i++) { cin>>a[i]; } sort(a+1,a+n+1); int l(0),r(n); while(l<r) { s+=pow(a[r]-a[l],2); l++; s+=pow(a[l]-a[r],2); r--; } cout<<s<<endl; return 0; } ``` 仅供参考
by yueyifan @ 2023-12-23 21:08:19


|