codeforces 429D】的更多相关文章

题链: http://codeforces.com/problemset/problem/429/D题解: 分治,最近点对 不难发现g(i,j)=sum[j]-sum[i], 那么f(i,j)=(i-j)²+(sum[j]-sum[i])² =(i-j)²+(sum[i]-sum[j])² 然后可以把(i,sum[i])看成平面上的点, 那么要求f(i,j)min就转变为了求平面上的最近点对问题. 用分治即可解决. 代码: #include<bits/stdc++.h> #define MAX…
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = Sj - Si f(i,j) = (i-j)^2 + (Si - Sj)^2 观察这个式子,我们发现可以用类似于平面最近点对的算法来求解该问题 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 const…
[题目链接]:http://codeforces.com/problemset/problem/429/D [题意] 给你n个数字; 让你求出一段区间[l,r] 使得 (r−l)2+(∑rl+1a[i])2最小 [题解] 求出前缀和数组sum[i]; 可以发现,如果把数组的下标i作为第一维坐标(x),前缀和sum[i]作为第二维坐标(y); 所求的式子就是任意两点之间的距离平方; 问题转化成:已知平面上的n个点; 求最近的两个点之间的距离的平方; 这个可以用分治的方法搞出来; (感觉就是个剪枝的…
题意:给定一个数组你个数的数组a,定义sum(i, j)表示sigma(a[i],...a[j]),以及另外一个函数f(i, j) = (i - j)^2 + sum(i+1, j)^2 求最小的f(i, j)(i < j) 思路:变形一下f(i, j) = (i - j)^2 + (sum[j] - sum[i])^2 那么把i看成x,sum[i]看成y,那就等价于求二维平面的最近点对吗. 二维平面求最近点对有一个经典nlognlogn的分治算法.. code: #include <bits…
题目链接  Tricky Function $f(i, j) = (i - j)^{2} + (s[i] - s[j])^{2}$ 把$(i, s[i])$塞到平面直角坐标系里,于是转化成了平面最近点对问题. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i) #define dec(i, a, b) for (int i(a); i >=…
D. Tricky Function time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important cont…
题目链接:点击打开链接 暴力出奇迹. 正解应该是近期点对.以i点为x轴,sum[i](前缀和)为y轴,求随意两点间的距离. 先来个科学的暴力代码: #include<stdio.h> #include<string.h> #include<vector> #include<algorithm> #include<iostream> #include<queue> using namespace std; #define N 10005…
D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/429/D Description Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The sele…
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题.. 今天,我们来扒一下cf的题面! PS:本代码不是我原创 1. 必要的分析 1.1 页面的获取 一般情况CF的每一个 contest 是这样的: 对应的URL是:http://codeforces.com/contest/xxx 还有一个Complete problemset页面,它是这样的:…
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the shi…