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…
题目链接  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: 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…
题目描述 Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of th…
裸的近期点对.... 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 imp…
[题目链接] 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个点; 求最近的两个点之间的距离的平方; 这个可以用分治的方法搞出来; (感觉就是个剪枝的…
传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In this problem you are to calculate the sum of all integers from 1 to n, b…
题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分析:数很大,关键是精度问题,刚开始用__int64和double发现都是不对的,后来发现用long long 可以过 代码: #include<bits/stdc++.h> using namespace std; #define LL long long LL a[]={,,,,,,,,, ,,…