#includeint sum(int* a, int n){ return (0 ==
n)?0:(sum(a,n-1) + a[n-1]);}void sum1(int* a, int n,int& s){ if(0 == n)
return; else {...
分类:
其他好文 时间:
2014-05-19 20:33:20
阅读次数:
381
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero....
分类:
其他好文 时间:
2014-05-16 01:34:36
阅读次数:
293
线段树维护的是区间有多少个空位置,每次查询第X个空位置在哪,sum[rt]>=X就向左区间找,sum[rt]
#include
#include
#include
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 55555;
int...
分类:
其他好文 时间:
2014-05-15 20:19:48
阅读次数:
256
和上一题一样,寻找第K个位置,只不过需要处理一下下一个位置在哪,画图看看就知道了。
#include
#include
#include
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 30000+5;
int sum[maxn<<...
分类:
其他好文 时间:
2014-05-15 20:07:28
阅读次数:
262
Given two binary strings, return their sum
(also a binary string).For example, a = "11" b = "1" Return "100".string
的操作,短string补位。两个“0”会输出一个“00”,要特殊处理...
分类:
其他好文 时间:
2014-05-15 17:47:57
阅读次数:
283
第五道树题,10分钟之内一遍AC。做树题越来越有feel~题目:求一棵树从root结点到叶子结点的最短路径。思路:仍然是递归。如果一个结点的左右子树任意一边为Null,该子树的minDepth应为非null子树的高度+1;如果一个结点的左右子树两边都非Null,则该子树的minDepth应为两个子树...
分类:
其他好文 时间:
2014-05-15 17:24:43
阅读次数:
226
为了照到点Point(x0,y0),圆心可以在一个范围内移动,我们设该范围为(x,y)(Vec[i].x,Vec[i].y)表示第如果圆心在这个范围内,则第i个点就一定能照到,sum表示为了能照到前i个点,最靠近右边的圆的边界坐标。#define
LOCAL#include#include#incl...
分类:
其他好文 时间:
2014-05-15 14:31:11
阅读次数:
237
简单点说其实Segment Tree就是二分法的灵活运用。
需要的基础知识:
1 二分法
2 二叉树
3 最好熟悉堆排序
操作就是二分法和堆排序巧妙地合并起来。
有了这些基础知识Segment Tree就没有任何难度了。
参考原文:
http://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/
...
分类:
其他好文 时间:
2014-05-15 13:33:33
阅读次数:
250
题意:给定一组数和另一个数,在这组数中找两个数,使它们的和等于给定的数
思路1: --> 错,因为题目要求返回下标。
1.排序
2.两个下标,一个指向头,一个指向尾
3.如果下标指向的两个元素相加大于给定的数,尾下标减一
如果小于,头下标加一
思路2: hash
1.用hash存储每个数的下标
2.数组,看hash[target-num[i]]是否存在
复杂度:时间O(n), 空间O(n)...
分类:
其他好文 时间:
2014-05-15 01:28:13
阅读次数:
297
[ 问题: ]
Given 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 two numbers such that they add up to the ta...
分类:
其他好文 时间:
2014-05-15 00:04:39
阅读次数:
377