菜鸟的菜
文章平均质量分 54
小菜鸟快点儿飞
这个作者很懒,什么都没留下…
展开
-
POJ——1001 Exponentiation 解题思路
Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many compu原创 2015-03-09 17:08:26 · 634 阅读 · 1 评论 -
大饼的排序
来源于编程之美的一摞烙饼的排序。2种实现思路: 1. 从底层开始排序 2. 从上面开始排序 从上面排序分三种情况,不翻转,翻转一次,翻转3次(最开始以为是2次●0●)。这样看第一种最优,但是第二种是首先想到的方法,所以也进行了实现。菜鸟很菜的一个程序,写出来安慰一下自己:我有做过(一种悲伤的气氛)。 下面是完整的算法,其中run()是第二种,runbottom是第一种。 class原创 2015-03-09 16:35:06 · 487 阅读 · 1 评论 -
C++小问题之string 变为 int
这是leetcode 中遇到的一个纠结了很久的问题,试过几种,总结如下: int a=247; char c[10]; string b 方法一:使用sprintf_s(或sprintf) sprintf_s(c,"%d",a); string b(c);在VS中使用sprintf会有一个warning,并且建议采用sprintf_s。 用哪个还是看情况吧,(leetcod原创 2015-03-17 17:08:28 · 521 阅读 · 0 评论 -
堆排序以及优先队列
算法导论中的堆排序。 主要的几个函数:三个宏用来表示取父节点和左右子节点,算法导论讲的很详细实现很简单#define PARENT(i)(i/2)#define LEFT(i)(2*i)#define RIGHT(i)(2*i+1)class Numbersort{public: Numbersort() { arry=NULL; n原创 2015-03-10 22:08:12 · 497 阅读 · 1 评论 -
Leetcode-N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题意:对于一个n皇后问题,返回解的个数 解题思路:基于N-Queens,这个II版的反而更简单,记录解的个数并返回即可。bool iv(vector<in原创 2015-07-14 19:18:33 · 359 阅读 · 0 评论 -
LeetCode-Permutations
Given a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 题意:求出一组数的全排 解题思路:对数字按原创 2015-07-14 19:02:20 · 315 阅读 · 0 评论 -
Leetcode-Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1]. 题意:对一原创 2015-07-14 19:07:31 · 263 阅读 · 0 评论