题目链接:51nod 1065 最小正子段和 房教说用前缀和做,然后看了别人博客懂了后就感觉,这个真有意思... #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; const int inf = 0x3f3f3f3f; pair<long long, int> sum[N]; int a[N]; int n; int main(){ int i, j;…
寻找包裹轮廓的最小正矩形:boundingRect 函数 返回矩阵应满足:① 轮廓上的点均在矩阵空间内.② 矩阵是正矩阵(矩形的边界与图像边界平行). Rect boundingRect(InputArray points); 唯一一个参数是输入的二维点集,可以是 vector 或 Mat 类型. 代码示例: #include<opencv.hpp> #include<iostream> using namespace cv; using namespace std; int ma…
题意: 青蛙 A 和 青蛙 B ,在同一纬度按照相同方向跳跃相同步数,A的起点为X ,每一步距离为m,B的起点为Y,每一步距离为 n,一圈的长度为L,求最小跳跃步数. 思路: 一开始按照追击问题来写,结果发现会求出来小数,而且按照追击问题写的话,一圈就能相遇,但是!青蛙的步数可没有小数,而且青蛙是跳跃的,显然不能在空中相遇吧. 所以咧,先列出一个追击的式子 ,设步数为 t ,整数为K(转了K圈以后他们才到同一个地方) t * m + x = t * n + y + k * L ===> t *…
uva 1411 Ants Description Young naturalist Bill studies ants in school. His ants feed on plant-louses that live on apple trees. Each ant colony needs its own apple tree to feed itself. Bill has a map with coordinates of n ant colonies and n apple tre…
现在我们将要叙述四个算法来求解早先提出的最大子序列和问题. 第一个算法,它只是穷举式地尝试所有的可能.for循环中的循环变量反映了Java中数组从0开始而不是从1开始这样一个事实.还有,本算法并不计算实际的子序列:实际的计算还要添加一些额外的代码. public static int maxSubSum1(int[] a) { int maxSum = 0; for(int i = 0;i<a.length;i++) for(int j = i;j<a.length;j++) { int th…
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solving complex problems by breaking them down into simpler sub-problems. It is applicable to problems exhibiting the properties of overlapping sub-problem…
Given strings S and T, find the minimum (contiguous) substring W of S, so that T is a subsequenceof W. If there is no such window in S that covers all characters in T, return the empty string "". If there are multiple such minimum-length windows…
D - POJ 2533 经典DP-最长上升子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. Fo…