题目链接:点击打开链接

暴力出奇迹。

正解应该是近期点对。以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 近期点对的更多相关文章

  1. Codeforces(429D - Tricky Function)近期点对问题

    D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces 429D Tricky Function(平面最近点对)

    题目链接  Tricky Function $f(i, j) = (i - j)^{2} + (s[i] - s[j])^{2}$ 把$(i, s[i])$塞到平面直角坐标系里,于是转化成了平面最近点 ...

  3. Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对

    D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...

  4. codeforce 429D. Tricky Function (思维暴力过)

    题目描述 Iahub and Sorin are the best competitive programmers in their town. However, they can't both qu ...

  5. Codefoces 429 D. Tricky Function

    裸的近期点对.... D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  6. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  7. 【codeforces 429D】Tricky Function

    [题目链接]:http://codeforces.com/problemset/problem/429/D [题意] 给你n个数字; 让你求出一段区间[l,r] 使得 (r−l)2+(∑rl+1a[i ...

  8. CodeForces - 598A Tricky Sum (数学,快速幂的运用)

    传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...

  9. codeforces 598A Tricky Sum

    题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分 ...

随机推荐

  1. zzulioj--1832--贪吃的松鼠(位运算好题)

    1832: 贪吃的松鼠 Time Limit: 3 Sec  Memory Limit: 2 MB Submit: 43  Solved: 7 SubmitStatusWeb Board Descri ...

  2. 隐藏tomcat nginx版本信息

    Tomcat --首先备份tomcat .首先找到这个jar包,$TOMCAT_HOME/lib/catalina.jar .解压catalina.jar之后按照路径\org\apache\catal ...

  3. POJ 3665 模拟

    按照题意模拟就OK了 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  4. java9新特性-17-智能Java编译工具

    1.官方Feature 139: Enhance javac to Improve Build Speed. 199: Smart Java Compilation, Phase Two 2.使用说明 ...

  5. UVa 1001 Say Cheese【floyd】

    题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置, 在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 看到n<=100,又是求最短时间,想到 ...

  6. UVa 10305 Ordering Tasks【拓扑排序】

    题意:给出n件事情,m个二元组关系,求它们的拓扑序列 用的队列来做 #include<iostream> #include<cstdio> #include<cstrin ...

  7. Eclipse StartExplorer插件

    http://www.cnblogs.com/wuxiang/p/5489961.html

  8. Liquibase被锁

    经常运行过程中出现 Liquibase - Waiting for changelog lock Waiting for changelog lock.... Running the migratio ...

  9. myeclipse2013 jsp编辑初始化

    首先,大家可能有过这种经历.双击打开jsp编辑.它默认会打开视图,这样就使人恼火了,卡死了.所以我们能够自己设jsp的默认打开方式:打开Window-->preferences得: 搜索edit ...

  10. CountDownLatch &amp; CyclicBarrier源代码实现解析

    CountDownLatch CountDownLatch同意一条或者多条线程等待直至其他线程完毕以系列的操作的辅助同步器. 用一个指定的count值对CountDownLatch进行初始化. awa ...