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的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分 ...
随机推荐
- poj_3468,线段树成段更新
参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/ #include<iostream> #include& ...
- 使用tinyxml2库解析xml
tinyxml2简介 tinyxml2是c++编写的轻量级的xml解析器,而且是开放源代码的,在一些开源的游戏引擎中用的比较多.源码托管在github上. 源码地址:https://github.co ...
- 如何用Java实现反转排序
摘要:反转排序是将原先已经排序好了的重新排序,是原来的数组元素的顺序反转过来.假设原来的数组顺序是{6,5,4,3,2,1},反转之后的顺序就是{1,2,3,4,5,6}.这个排序的算法不是很难,代码 ...
- 推荐《R数据可视化手册》高清英文版PDF+中文版PDF+源代码
绝大多数的绘图案例都是以强大.灵活制图而著称的R包ggplot2实现的,充分展现了ggplot2生动.翔实的一面.从如何画点图.线图.柱状图,到如何添加注解.修改坐标轴和图例,再到分面的使用和颜色的选 ...
- 修复linux的grub2引导(单独/boot,lvm-root)
root@ubuntu:/home/ubuntu# pwd /home/ubuntu root@ubuntu:/home/ubuntu# lsblk NAME MAJ ...
- python3 geohash 导入错误及解决
方法一: pip3 install python-geohash 方法二: 1.保证 pip3 install geohash 包 2. 进入包的下载目录 /usr/local/lib/python ...
- QQ音乐
import re import requestsimport json class Search: def __init__(self, song): ''' self.vkey_url ---&g ...
- 洛谷 P1454 圣诞夜的极光
P1454 圣诞夜的极光 题目背景 圣诞夜系列~~ 题目描述 圣诞老人回到了北极圣诞区,已经快到12点了.也就是说极光表演要开始了.这里的极光不是极地特有的自然极光景象.而是圣诞老人主持的人造极光. ...
- 零基础学python-5.6 数字位操作与其它工具
1.位运算 python能够把整数当成二进制位来对待 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/ ...
- 大型网站架构之JAVA中间件
中间件就是在大型网站中,帮助各子模块间实现互相访问,消息共享或统一访问等功能的软件产品.常见的有: 远程服务框架中间件:主要解决各子模块之间互相访问的问题. 消息队列中间件:主要解决各子模之间消息共享 ...