摘要: How to solve this HARD issue1. Problem: A non-empty zero-indexed array A consisting of N integers is given.Apeakis an array element which is larger th... 阅读全文
posted @ 2015-01-19 21:54 sjtubear 阅读(1250) 评论(0) 推荐(0) 编辑
摘要: 在面对整数时,要留心整数溢出的情况。 在探索一个数有多少个除数的程序中,原本我们只要累加自然数到大于根号N停止即可。 不过因为计算机的整数范围的限制,我们需要判断是否i*i<(i-1)*(i-1)。 如果发生这种情况,说明整数溢出了~ 阅读全文
posted @ 2015-01-19 17:57 sjtubear 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 以为所有N的除数都是以根号N为轴对称的。 例如16的开方为4; 16%1 == 0 则1 与 16 都是16的除数。 16%2 == 0 则2 与 8 都是16的除数。 16%4 ==0 则4 为16 的除数。 如果继续查找,找到 8 则已经添加。 所以判断一个数为质数与否的复杂度为O(根号N) 阅读全文
posted @ 2015-01-19 17:23 sjtubear 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 1. 上题目:Task descriptionA non-empty zero-indexed array A consisting of N integers is given.A triplet (X, Y, Z), such that 0 ≤ X 0)18 {19 ... 阅读全文
posted @ 2015-01-19 17:14 sjtubear 阅读(970) 评论(0) 推荐(0) 编辑
摘要: 对于使用stack进行()的配对检查,不需要使用额外的空间对每个字符进行存储和push与pop的操作。 只使用size对()进行处理即可,因为只有一种括号,所以入栈为size加1,出栈为size-1.如果size<0,说明配对失败。 这样将空间从O(N)降为O(1); 阅读全文
posted @ 2015-01-19 10:33 sjtubear 阅读(130) 评论(0) 推荐(0) 编辑
摘要: A string S consisting of N characters is considered to be properly nested if any of the following conditions is true:S is empty; S has the form "(U)" ... 阅读全文
posted @ 2015-01-19 10:17 sjtubear 阅读(294) 评论(0) 推荐(0) 编辑
摘要: Given an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc and K-th disc intersect if J ≠ K and J-th... 阅读全文
posted @ 2015-01-19 09:34 sjtubear 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 1 / you can write to stdout for debugging purposes, e.g. 2 // printf("this is a debug message\n"); 3 #include 4 5 int cmp(const void*p1,const void*... 阅读全文
posted @ 2015-01-19 00:04 sjtubear 阅读(225) 评论(0) 推荐(0) 编辑