题目链接:点击打开链接

暴力出奇迹。

正解应该是近期点对。以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. 【转】dig详解

    [root@localhost ~]# dig www.a.com ; <<>> DiG 9.2.4 <<>> www.a.com ;; global ...

  2. 安卓开发--AsyncTask2

    package com.cnn.imageasyncdemo01; import android.app.Activity; import android.content.Intent; import ...

  3. BZOJ 3083 树链剖分+倍增+线段树

    思路: 先随便选个点 链剖+线段树 1操作 就直接改root变量的值 2操作 线段树上改 3操作 分成三种情况 1.new root = xx 整个子树的min就是ans 2. lca(new roo ...

  4. MetaSploit攻击实例讲解------工具Meterpreter常用功能介绍(kali linux 2016.2(rolling))(详细)

    不多说,直接上干货! 说在前面的话 注意啦:Meterpreter的命令非常之多,本篇博客下面给出了所有,大家可以去看看.给出了详细的中文 由于篇幅原因,我只使用如下较常用的命令. 这篇博客,利用下面 ...

  5. jquery批量绑定click事件

    jquery批量绑定click事件: var selects = $(".public_select dd ul li"); debugger; /*$(".public ...

  6. angular route 与 django urls 冲突怎么解决?

    app.js var app = angular.module('app', [ 'ngResource', 'ngRoute', // 'ui.bootstrap', // 'ngResource' ...

  7. PostgreSQL服务器存储参数的内部查看方法和实际表述之间的关系

    postgres=# show wal_buffers ; wal_buffers ------------- 4MB(1 row) postgres=# show port; port ------ ...

  8. [NOI2010]海拔 平面图转对偶图 最小割

    题解: 首先,我们不难猜到高度只有 $0$ 或 $1$ 两种可能,而且高度为 0 的地区组成一个联通块,高度为 1 的地区组成一个联通块.只有这样,人们所耗费的体力才是最小的.得出这个结论,题目就成了 ...

  9. 编译php并与nginx整合

    告诉 Nginx 如何处理 php 文件:          nginx>vim  conf/nginx.conf                     location ~ \.php${ ...

  10. [转载]-win7启动本地MongoDB的四种方式

    2016年04月07日 09:52:34 cherry__cheng 阅读数:19451 标签: win7启动本地MongoDB的四种方式快速启动本地mongodb 更多 个人分类: mongodb& ...