def sumS(s):
if s 1:
if cursum < s:
last += 1
cursum += last
else:
if cursum == s:
re.append((...
分类:
其他好文 时间:
2014-07-03 16:42:24
阅读次数:
190
def q32(n, len):
if n < 0:
return 0
elif n 0:
if n >= 1 and n < 10:
total += 1
return total
p1 = n % (10**(len - 1))
h = n / (10**(len - 1))
...
分类:
编程语言 时间:
2014-07-03 16:04:12
阅读次数:
288
书里面关于分类的判断有些麻烦,通过某一位为0为1来对数组元素进行分类。假如第3位为1,那么也就是元素x & 8 等于或不等于0,所以没必要非的用第几位去判断。
def once(array):
reOR = 0
for x in array:
reOR ^= x
bit1 = firstBit1(reOR)
first = 0
second = 0
for x in a...
分类:
其他好文 时间:
2014-07-03 13:54:06
阅读次数:
182
分析:
假如给定的数组中的元素是1-9之间的数,我们怎么来处理呢?比如[ 1,4,7,9,3,8],很简单,排个序,就是134789。
这里不同的一点就是,给定的数稍微复杂一点,不再单纯的是1位的数,[3,32,321] 这种情况也会出现。我们还想用排序,那么就需要自己制定下排序规则,也就是比较的标准。
str1和str2 长度相同的比较就不说了,在长度不同的时候,我们将长度短的用最后一位进...
分类:
其他好文 时间:
2014-07-02 11:47:35
阅读次数:
209
排序,在编程中经常遇到的算法,我也在几篇文章中介绍了一些关于排序的算法。有的高级语言内置了一些排序函数。本文讲述Python在这方面的工作。供使用python的程序员们参考,也让没有使用python的朋友了解python。领略一番“生命有限,请用Python”的含义。
内置函数sorted()/list.sort()的使用
简单应用
python对list有一个内置函数:...
分类:
编程语言 时间:
2014-07-02 09:41:58
阅读次数:
224
题目大意:
求可覆盖的出现k次的子串的最大长度。
思路分析:
同样是二分答案的长度,然后扫描height判断是否成立。
#include
#include
#include
#include
#define maxn 1000005
using namespace std;
int str[maxn];
int sa[maxn],t1[maxn],t2[maxn]...
分类:
其他好文 时间:
2014-07-02 09:02:19
阅读次数:
258
构造系数矩阵,高斯消元求解二次函数,然后两点式求直线函数,带入辛普森积分法无脑AC。。。
#include
#include
#include
#include
#include
#include
using namespace std;
struct node
{
double x,y;
}p[4];
double g[10][10];
double f1(double x) //二次...
分类:
其他好文 时间:
2014-07-02 07:56:59
阅读次数:
313
基本枚举、贪心、递归、分治、递推、模拟STL(pair、vector、set、map、queue、string、algorithm)构造、位运算、常数优化数据结构队列、堆、栈、链表排序(插入、冒泡、快速、归并、堆、桶、基数)二分查找、散列表并查集、哈夫曼树排序二叉树、左偏树、平衡树(Splay/Tr...
分类:
其他好文 时间:
2014-07-01 19:09:02
阅读次数:
193
题目
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it witho...
分类:
其他好文 时间:
2014-07-01 06:24:42
阅读次数:
204
题目
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it...
分类:
其他好文 时间:
2014-07-01 06:23:24
阅读次数:
334