摘要:
刷水题判断有多少个素数。关键点避免超时。http://acm.hdu.edu.cn/showproblem.php?pid=2138View Code #include <stdio.h>#include <math.h>int isPrimer(unsigned int n ){ int i ; unsigned int m = sqrt(n); for(i = 2; i <= m; ++i) { if(!(n % i )) break; } return i > m;}int main(){ int n,m; ... 阅读全文
摘要:
题目:You are given an array A that contains integers. Every integer occurs 3 times in A leaving one integer that appears only once. Fastest way to find that single integer.分析:如果这里的数组A的规模比较小,在内存的可以容纳的范围之内,可以建立hash表,顺序扫描A中的每一个 数,统计每个数的出现次数,最后找出仅出现一次的数即可,时间复杂度为O(N),空间复杂度为O(N)。如果数组A的规模很大呢?难道是进行外排序,然后 通过me 阅读全文