求矩阵的模: function count = juZhenDeMo(a,b) [r,c] = size(a);%求a的行列 [r1,c1] = size(b);%求b的行列 count = 0; for j=1:r-r1+1%所求的行数中取 for i=1:c-c1+1%所有的列数中取 d = a(j:j+r1-1,i:i+c1-1); e = double(d==b); if(sum(e(:))==r1*c1) count = count + 1; end end end<pre name=
题目:Park Visit 题意:给定一棵树,从树中的任意选一个顶点出发,遍历K个点的最短距离是多少?(每条边的长度为1) 解析:就是求树的最长链,假设求出的树的最长链所包含的点数为m,那么如果K<=m,那么答案就是K-1,否则就是(K-m)*2+m-1 #include <iostream> #include <string.h> #include <stdio.h> using namespace std; const int N=200010; int he
In the math class, the evil teacher gave you one unprecedented problem! Here f(n) is the n-th fibonacci number (n >= 0)! Where f(0) = f(1) = 1 and for any n > 1, f(n) = f(n - 1) + f(n - 2). For example, f(2) = 2, f(3) = 3, f(4) = 5 ... The teacher u
问题是这样,如果我们知道两个向量v1和v2,计算从v1转到v2的旋转矩阵和四元数,由于旋转矩阵和四元数可以互转,所以我们先计算四元数. 我们可以认为v1绕着向量u旋转θ角度到v2,u垂直于v1-v2平面. 四元数q可以表示为cos(θ/2)+sin(θ/2)u,即:q0=cos(θ/2),q1=sin(θ/2)u.x,q2=sin(θ/2)u.y,q3=sin(θ/2)u.z 所以我们求出u和θ/2即可,u等于v1与v2的叉积,不要忘了单位化:θ/2用向量夹角公式就能求. ma
Simpsons' Hidden Talents Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4597 Accepted Submission(s): 1671 Problem Description Homer: Marge, I just figured out a way to discover some of the
题记: 这道题不难但是很有意思,有两种解题思路,可以说一种是横向扫描,一种是纵向扫描. 横向扫描:遍历所有字符串,每次跟当前得出的最长公共前缀串进行对比,不断修正,最后得出最长公共前缀串. 纵向扫描:对所有串,从字符串第0位开始比较,全部相等则继续比较第1,2...n位,直到发生不全部相等的情况,则得出最长公共前缀串. 横向扫描算法实现: //LeetCode_Longest Common Prefix //Written by zhou //2013.11.22 class Solution
Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18472 Accepted: 7318 Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay s