码迷,mamicode.com
首页 >  
搜索关键字:容器析构出错 vector    ( 11651个结果
10375 - Choose and divide(唯一分解定理的运用 eratosthenes构造素数表)
我觉得数学类的题目,每一道都有很好的解决方法,都很有保存的意义和价值。 这道题目里面,巧妙地运用了 唯一分解定理,辅以素数的eratosthenes筛法构造,很好地解决了题目。值得思考和深入的学习。 #include #include #include #include #include using namespace std; vector primes; const int ma...
分类:其他好文   时间:2014-08-11 17:57:02    阅读次数:158
代码简洁之道:C++ 11 之auto+ for_each + lamda表达式
摘要:在很多中情况下,我们需要这样的运算:给vector中每个元素进行相似的处理(每个元素+1,或者其他).一般情况下,我们会选用for循环,然后然后对每个元素进行处理。实际上,C++ 11提供了了lamda表达式,结合for_each,可以写出更加简洁和高效的代码。 1.for_each.简介 for_each是C++中的模板,具体用法可以参考这里:http://www.cplusp...
分类:编程语言   时间:2014-08-11 15:05:52    阅读次数:218
条款十三: 初始化列表中成员列出的顺序和它们在类中声明的顺序相同
templateclass array {public: array(int lowbound, int highbound); ...private: vector data; // 数组数据存储在vector对象中 ...
分类:其他好文   时间:2014-08-11 14:49:42    阅读次数:174
STL vector中的crbegin方法(7)
其实crbegin就相当于cbegin+rbegin. 关于这两个函数可以看我的上两篇博文。 public member function std::vector::crbegin const_reverse_iterator crbegin() const noexcept; Return const_reverse_iterator to ...
分类:其他好文   时间:2014-08-11 08:27:33    阅读次数:262
LeetCode--Sudoku Solver
思路:dfs+数独游戏规则。数独游戏规则是:同行同列不能有重复数字;并且每9宫内不能有重复数字 1 class Solution { 2 public: 3 bool isValid(vector > &board, int a, int b) { 4 int i,j; 5 ...
分类:其他好文   时间:2014-08-10 23:58:20    阅读次数:431
HDOJ 2647 Reward 【逆拓扑排序+分层】
题意:每个人的基础工资是888, 由于一部分人要显示自己水平比较高,要求发的工资要比其他人中的一个人多,问你能不能满足他们的要求,如果能的话最终一共要发多少钱,如果不能就输出-1. 策略:拓扑排序。 这道题有些难点:一:数据大,建二维数组肯定不行,要换其他的数据结构(vector, 或者是链式前向星(本题代码用的是链式前向星)); 二:要逆拓扑排序(就是将++in[b]换成++in[a]),...
分类:其他好文   时间:2014-08-10 18:39:00    阅读次数:250
vector
#include //从小到大排列#include#includeusing namespace std;int main(){ int i,x; vectormy ; for(i=1;i>x; my.push_back(x); } sort(my.begin(),my.end()); f...
分类:其他好文   时间:2014-08-10 18:34:30    阅读次数:188
poj 1330 Nearest Common Ancestors (LCA)
题意:求两个点的最近公共祖先。 1A#include #include #include #include #define maxn 100010 using namespace std; int fa[maxn],lev[maxn],pre[maxn],c1,c2; vector son[maxn]; bool dfs(int rt,int obj) { for(int i...
分类:其他好文   时间:2014-08-10 15:42:40    阅读次数:261
记得适当的声明成员函数为const.
如果确信一个成员函数不用修改它的对象,就可以声明它为const,这样就可以作用于他的const对象了.因为const对象只能调用它的const方法. 1 template class Vector 2 { 3 public: 4 int length() const//如果这里没有const...
分类:其他好文   时间:2014-08-10 15:27:10    阅读次数:179
快速排序 归并排序的非递归版本 备忘
首先,归并排序,分治,递归解决小的范围,再合并两个有序的小范围数组,便得到整个有序的数组。 这是很适合用递归来写的,至于非递归,便是从小到大,各个击破,从而使得整个数组有序。代码如下: void merge(vector &A, int left, int mid, int right) { int i=left,j=mid+1; vector tmp(right-left+1,0);...
分类:其他好文   时间:2014-08-10 13:08:00    阅读次数:235
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!