1、同余定理
(a+b)%c==(a%c+b%c)%c
(a*b)%c==[(a%c)*(b%c)]%c
因为有的数在int范围内,但是两个的乘积却超过了int范围,这样可以避免运算过程中超过int范围
2、gcd函数(即最大公约数)
int gcd(int a,int b)
{
return !b?a:gcd(b,a%b);
}...
分类:
其他好文 时间:
2014-07-25 11:09:31
阅读次数:
187
Given a binary tree, return the inorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
比较简单,就是转化成中序遍历即可,访问顺序是中序遍历左子树,根节点,中序遍历右子树
Python编程的时候需要注意,要在返回单一数字的时候加...
分类:
编程语言 时间:
2014-07-25 11:07:51
阅读次数:
221
C# wpf程序获取当前程序版本号
///
/// 获取当前系统的版本号
///
///
public static string GetEdition()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToStri...
分类:
其他好文 时间:
2014-07-25 11:06:01
阅读次数:
741
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题解,很巧妙的一道题,对于一个0-1矩阵,它的每一行及以上都可以看...
分类:
其他好文 时间:
2014-07-25 10:53:01
阅读次数:
292
Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the...
分类:
其他好文 时间:
2014-07-25 03:15:41
阅读次数:
176
Length of Last WordGiven a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.I...
分类:
其他好文 时间:
2014-07-25 02:26:04
阅读次数:
322
在angular中我们定义directive方法时,可以看到
return {
restrict: 'AE',
scope: {},
template: '',
link: function() {}
}
除了代码中出现的属性,还有一些其他的属性可供配置,这里不作详述。
今天我们要说的重点是scope字段。
常规用法设置...
分类:
Web程序 时间:
2014-07-24 23:38:23
阅读次数:
319
树状数组+二分
就是找第几小的数,,找几次,再求和。。
#include
#include
#include
#include
#include
using namespace std;
const int N=277777;
int t,n,m,bit[N],num,i;
long long ans;
int low(int g)
{
return g&(-g);
}
void up...
分类:
其他好文 时间:
2014-07-24 23:29:33
阅读次数:
266
# include
# include
# include
using namespace std;
struct node
{
int v;
int t;
};
struct node a[100010];
bool cmp(node a,node b)
{
return a.v *a.t+(a.v+b.v)*b.t<b.v*b.t+(a.v+b.v)*a.t;
}...
分类:
其他好文 时间:
2014-07-24 23:16:23
阅读次数:
268
求一组数据的最小公倍数。
先求公约数在求公倍数,利用公倍数,连续求所有数的公倍数就可以了。
#include
int GCD(int a, int b)
{
return b? GCD(b, a%b) : a;
}
inline int LCM(int a, int b)
{
return a / GCD(a, b) * b;
}
int main()
{
int T, m, a,...
分类:
其他好文 时间:
2014-07-24 23:13:03
阅读次数:
203