题目链接:点击打开链接
暴力出奇迹。
正解应该是最近点对,以i点为x轴,sum[i](前缀和)为y轴,求任意两点间的距离。
先来个科学的暴力代码:
#include<stdio.h> #include<string.h> #include<vector> #include<algorithm> #include<iostream> #include<queue> using namespace std; #define N 100050 #define ll __int64 ll a[N], sum[N]; ll n; int main(){ ll u, v, i, j, que; sum[0] = 0; while(~scanf("%I64d",&n)){ for(i=1;i<=n;i++)scanf("%I64d",&a[i]),sum[i] = sum[i-1]+a[i]; ll ans = a[2]*a[2]+1; for(i = 1; i <= n; i++){ if(i*i>=ans)break; ll tmp = ans; for(j = i+1; j<=n; j++){ tmp = min(tmp, (sum[j]-sum[j-i])*(sum[j]-sum[j-i])); } ans = min(ans, tmp+i*i); } printf("%I64d\n",ans); } return 0; }
Codeforces 429D Tricky Function 最近点对,布布扣,bubuko.com
Codeforces 429D Tricky Function 最近点对
原文地址:http://blog.csdn.net/acmmmm/article/details/25626039