求一组数据的最小公倍数。
先求公约数在求公倍数,利用公倍数,连续求所有数的公倍数就可以了。
#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
原始题目例如以下,意为寻找数组和最大的子串,返回这个最大和就可以。Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, ...
分类:
其他好文 时间:
2014-07-23 15:45:59
阅读次数:
246
题意:
要求在一个特殊的图上找最大匹配,该图特点是:无向图,每个节点度数为3,是一个边双连通分量(the graph is 2-edge-connected (that is, at least 2 edges need to be removed in order to make the graph disconnected) 这一点是这样理解的把。。)
思路:
一般想法就直接建图求最大匹...
分类:
其他好文 时间:
2014-07-23 13:22:07
阅读次数:
207
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n.
The i-th child wants to get at least ai candies.
Jzzhu asks childre...
分类:
其他好文 时间:
2014-07-22 22:49:13
阅读次数:
237
并查集(Union-find Sets)是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题。一些常见的用途有求连通子图、求最小生成树的 Kruskal 算法和求最近公共祖先(Least Common Ancestors, LCA)等。
使用并查集时,首先会存在一组不相交的动态集合 S={S1,S2,?,Sk},一般都会使用一个整数表示集合中的一个元素。
每个集合可能包含一个...
分类:
其他好文 时间:
2014-07-19 23:23:29
阅读次数:
378
Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29480 Accepted Submission(s): 11136
Problem Description
The le...
分类:
其他好文 时间:
2014-07-19 23:14:59
阅读次数:
244
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
分类:
其他好文 时间:
2014-07-19 12:13:13
阅读次数:
254
最小公倍数=两个数的乘积/两个数的最大公约数。
接上篇求最大公约数方法,最小公倍数的代码如下:
public class LCM {
//最小公倍数=两数乘积/最大公约数
public static int lcm(int m, int n){
return m*n/GCD.gcd(m,n);
}
public static void main(String[] args){
...
分类:
其他好文 时间:
2014-07-16 09:39:09
阅读次数:
256
1、错误原因
2014-7-13 17:36:57 org.apache.jasper.compiler.TldLocationsCache tldScanJar
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete...
分类:
编程语言 时间:
2014-07-14 13:44:07
阅读次数:
325
TreeYou are to determine the value of the leaf node in a given binary tree that is the terminal node of a path of least value from the root of the bin...
分类:
其他好文 时间:
2014-07-13 21:24:22
阅读次数:
202