![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 63
daweibayu123
这个作者很懒,什么都没留下…
展开
-
算法小记
在论坛上看到一道百度的面试题,有个自己感觉不错的想法,记下,嘿嘿 题目如下: 实现一个函数,对一个正整数n,算得到1需要的最少操作次数。操作规则为:如果n为偶数,将其除以2;如果n为奇数,可以加1或减1;一直处理下去 例子: func(7) = 4,可以证明最少需要4次运算 n = 7 n-1 6 n/2 3 n-1 2 n/2 1 要求:实现函数(实现尽可能高效) int原创 2012-03-20 19:16:41 · 347 阅读 · 0 评论 -
快速排序
中心思想:分治 看到不少快排的变种,但是中心思想都是不变的,分治,不管是从左往右遍历也好,还是从两边往中间遍历也好,其实都是想把数据分到主元两边,其实拓展一下,主元也未必非是只有一个,两个主元,然后遍历数据分成三部分也可,只是算法实现起来稍复杂。 暂记原创 2013-09-11 23:10:48 · 427 阅读 · 0 评论 -
poj 1007
#include #include #include #include using namespace std; struct DNAChain { string chain; int measure; }; int compare(const DNAChain& chain1, const DNAChain& chain2) { return chain1.measure < c原创 2013-10-04 12:19:57 · 455 阅读 · 0 评论 -
poj 1002
#include #include #include using namespace std; char telephoneMap[] ={'2', '2', '2', '3', '3', '3', '4', '4', '4', '5', '5', '5', '6', '6', '6', '7', '0', '7', '7', '8', '8', '8', '9', '9', '9', '0原创 2013-10-04 21:51:10 · 466 阅读 · 0 评论 -
poj 1220
#include #include using namespace std; int charToNum(char element) { if(element <= '9') return element - '0'; else if(element = 'A') return element - 'A' + 10; else if(element = 'a') retur原创 2013-10-09 14:11:14 · 557 阅读 · 0 评论 -
poj 1546
#include #include #include using namespace std; int charToNum(char element) { if(element <= '9') return element - '0'; else if(element = 'A') return element - 'A' + 10; else if(element = 'a原创 2013-10-09 14:24:24 · 533 阅读 · 0 评论 -
poj 2105
#include #include using namespace std; char numToChar(int num) { return num + '0'; } int baseStrToInt(const string& sequence, int base) { int result = 0; for(int i = 0; i < sequence.length();原创 2013-10-09 15:39:12 · 573 阅读 · 0 评论 -
字符串旋转
问题: 把字符串前面的若干个字符移动到字符串的尾部。如把字符串abcdef前2位字符移到后面得到字符串cdefab。要求时间对长度为n的字符串操作的复杂度为O(n),辅助内存为O(1)。 看到大多数的帖子都是进行三次旋转 如:http://blog.csdn.net/v_JULY_v/article/details/6322882 个人感觉这思路确实比较新颖,但是总感觉有点原创 2013-10-10 12:30:57 · 404 阅读 · 0 评论