Codeforces 429D Tricky Function 近期点对
题目链接:点击打开链接
暴力出奇迹。
正解应该是近期点对。以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 近期点对的更多相关文章
- Codeforces(429D - Tricky Function)近期点对问题
D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 429D Tricky Function(平面最近点对)
题目链接 Tricky Function $f(i, j) = (i - j)^{2} + (s[i] - s[j])^{2}$ 把$(i, s[i])$塞到平面直角坐标系里,于是转化成了平面最近点 ...
- Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对
D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...
- codeforce 429D. Tricky Function (思维暴力过)
题目描述 Iahub and Sorin are the best competitive programmers in their town. However, they can't both qu ...
- Codefoces 429 D. Tricky Function
裸的近期点对.... D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【codeforces 429D】Tricky Function
[题目链接]:http://codeforces.com/problemset/problem/429/D [题意] 给你n个数字; 让你求出一段区间[l,r] 使得 (r−l)2+(∑rl+1a[i ...
- CodeForces - 598A Tricky Sum (数学,快速幂的运用)
传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...
- codeforces 598A Tricky Sum
题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分 ...
随机推荐
- PHPStorm打开文件所在目录
很实用~
- spark 数据预处理 特征标准化 归一化模块
#We will also standardise our data as we have done so far when performing distance-based clustering. ...
- 木马——本质就是cs socket远程控制,反弹木马是作为c端向外发起网络请求
摘自:http://kczxsp.hnu.edu.cn/upload/20150504165623705.pdf 里面对于木马的实验过程写得非常清楚,值得一看. 木马是隐藏在正常程序中的具有特殊功 ...
- HBase框架基础(五)
* HBase框架基础(五) 本节主要介绍HBase中关于分区的一些知识. * HBase的RowKey设计 我们为什么要讨论rowKey的设计?或者说为什么很多工作岗位要求有rowKey的优化设计经 ...
- js文字的无缝滚动(上下)
使用scrolltop值的递增配合setInterval与setTimeout实现相关效果,左右无缝滚动使用scrollLeft即可 Dom内容 <div id="container& ...
- highGUI图形用户界面
#include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> using namespace ...
- k近邻法(k-nearest neighbor, k-NN)
一种基本分类与回归方法 工作原理是:1.训练样本集+对应标签 2.输入没有标签的新数据,将新的数据的每个特征与样本集中数据对应的特征进行比较,然后算法提取样本最相似数据(最近邻)的分类标签. 3.一般 ...
- [HAOI2007]理想的正方形 单调队列 暴力
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; #d ...
- 洛谷1726 上白泽慧音 tarjan模板
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- 中国象棋程序的设计与实现(十一)--第2次回答CSDN读者的一些问题
最近一段时间,有不少CSDN读者朋友看了我写的中国象棋文章.其中,不少爱好者下载了中国象棋程序的初级版和高级版源码. 由于水平有限,不少同学遇到了若干问题,向我咨询,寻找解决办法. 我的处境1.如果我 ...