码迷,mamicode.com
首页 >  
搜索关键字:xor sum    ( 22663个结果
[LeetCode]3Sum
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
ZOJ 3635 线段树
线段树维护的是区间有多少个空位置,每次查询第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
wikioi 1282 约瑟夫问题 线段树
和上一题一样,寻找第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
[LeetCode] [Add Binary 2012-04-02 ]
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
外星人的供给站(贪心)
为了照到点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 - Sum of given range
简单点说其实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
leetcode第一刷_3Sum
估计大家都会做twoSum,一头一尾两个指针,跟据和的大小移动就行了。 3sum能不能用相同的方法呢,我尝试用暴力做,居然过了。思路是先把数组排个序,让相同数字的都靠在一起,然后固定一个数,其他两个数就按照twosum的那一套来,只不过计算sum的时候多算了一个数而已。需要注意一个问题,靠在一起一样的数,只能在第一次遇到它的时候用,更准确一点说,每个相同的数,只有一次作为i或j或k的机会,而且不...
分类:其他好文   时间:2014-05-15 01:29:41    阅读次数:248
Leetcode 线性表 Two Sum
题意:给定一组数和另一个数,在这组数中找两个数,使它们的和等于给定的数 思路1: --> 错,因为题目要求返回下标。 1.排序 2.两个下标,一个指向头,一个指向尾 3.如果下标指向的两个元素相加大于给定的数,尾下标减一 如果小于,头下标加一 思路2: hash 1.用hash存储每个数的下标 2.数组,看hash[target-num[i]]是否存在 复杂度:时间O(n), 空间O(n)...
分类:其他好文   时间:2014-05-15 01:28:13    阅读次数:297
【LeetCode】- Two Sum(两数相加)
[ 问题: ] 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
鸽巢原理-poj3370
#include int main(int argc, char *argv[]){ int c = -1, n = -1; while (true) { scanf("%d%d",&c,&n); int arr[n],sum[n],b[n]; if (c + n == 0) { ...
分类:其他好文   时间:2014-05-14 23:11:50    阅读次数:391
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!