上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 16 下一页

2014年5月19日

获得第二大的元素

摘要: #includeusing namespace std;int main(){ int s1 = 1; unsigned int s2 = 1; cout>和逻辑右移(不带符号)>>>。 //算术右移:符号位不变,左边补上符号位。如: 1000 1000 >> 3 为 1111 0001 //逻辑右... 阅读全文

posted @ 2014-05-19 10:44 berkeleysong 阅读(175) 评论(0) 推荐(0) 编辑

2014年5月18日

数组祛除重复

摘要: #include#include#includeusing namespace std;void helper(int a[],const int n){ sort(a,a+n); int k = 0; for(int i = 0;i< n;i++) { if(a[i] != a[k])... 阅读全文

posted @ 2014-05-18 22:47 berkeleysong 阅读(97) 评论(0) 推荐(0) 编辑

左边为奇数,右边为偶数

摘要: #include#include#includeusing namespace std;void helper(int a[],const int n){ int left = 0; int right = n-1; while(leftleft) right--; ... 阅读全文

posted @ 2014-05-18 22:02 berkeleysong 阅读(161) 评论(0) 推荐(0) 编辑

找到符合条件的对数

摘要: #include#include#includeusing namespace std;int helper(int a[],int n, int t){ sort(a,a+n); int k = 0; int left = 0; int right = n-1; while(left t... 阅读全文

posted @ 2014-05-18 21:44 berkeleysong 阅读(124) 评论(0) 推荐(0) 编辑

找出出现奇数次的元素

摘要: #includeusing namespace std;bool question1(const int a[],const int n, int &num){ int temp = 0; for(int i = 0;i>1; k++; } num1 = 0; ... 阅读全文

posted @ 2014-05-18 21:24 berkeleysong 阅读(207) 评论(0) 推荐(0) 编辑

找到数组中唯一重复的数

摘要: #include#include#includeusing namespace std;int helper1(int a[],int n){ int sum = accumulate(a,a+n,0); int sum2 = n*(n-1)/2; return sum-sum2;}int h... 阅读全文

posted @ 2014-05-18 19:52 berkeleysong 阅读(173) 评论(0) 推荐(0) 编辑

在O(n)时间复杂度内找到出现超过一半的数

摘要: #includeusing namespace std;bool solver(const int a[],const int n, int & num){ if(NULL == a || 0>= n) return false; ////注意,是小写~ int count = 0; ... 阅读全文

posted @ 2014-05-18 19:29 berkeleysong 阅读(133) 评论(0) 推荐(0) 编辑

寻找数组中重复次数最多的数

摘要: #include#includeusing namespace std;int helper(const int a[],const int n){ map m; for(int i = 0;i::iterator comp = m.begin(); for( map::iterator it... 阅读全文

posted @ 2014-05-18 18:40 berkeleysong 阅读(235) 评论(0) 推荐(0) 编辑

第十一章 泛型算法 C++ PRIMER

摘要: vector::const_iterator result = find(vector.begin(). vector.end(),search_value); 如果查找失败,分会end() 如果有两个,会返回哪一个的迭代器?int *reauslt = find(ia,ia+6,search_va... 阅读全文

posted @ 2014-05-18 14:32 berkeleysong 阅读(132) 评论(0) 推荐(0) 编辑

2014年5月17日

动态规划题目

摘要: 动态规划算法,在T大某位老师的书中说就是递推+重复子问题。动态规划算法的效率主要与重复子问题的处理有关。典型的题目有 陪审团,最大公共子串问题1,最大公共子串问题这个是动态规划的基础题目。动态规划就是递推和重复子结构。确定了递推关系后。找到一个能极大地减少重复运算的子结构至关重要。选的好了,时间效率... 阅读全文

posted @ 2014-05-17 20:48 berkeleysong 阅读(242) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 16 下一页

导航