c++中,Deque容器和vector相似,deque内部也采用动态数组来管理元素,支持随机存取。。头文件1.deque和vector的不同之处:1)两端都可以较快速地按插元素和删除元素,而vector只能在尾端进行2)在对内存有所限制的系统中,deque可以包含更多的元素,因为它不止一块内存。因此...
分类:
编程语言 时间:
2014-05-01 10:10:02
阅读次数:
500
判断valid,没有更好的方法,只能brute force。 1 class Solution { 2
public: 3 bool isValidSudoku(vector > &board) { 4 5 int n; 6 for (int...
分类:
其他好文 时间:
2014-05-01 08:54:28
阅读次数:
332
思路很简单,就是存储之前运算的结果,然后递归class Solution {public: int**
dp; int get_min_sum(vector > &grid, int m, int n) { if (dp[m][n] != -1)
...
分类:
其他好文 时间:
2014-05-01 07:54:47
阅读次数:
330
在c++中,vector是一个十分有用的容器,下面对这个容器做一下总结。1
基本操作(1)头文件#include.(2)创建vector对象,vector
vec;(3)尾部插入数字:vec.push_back(a);(4)使用下标访问元素,cout::iteratorit;for(it=vec.b...
分类:
编程语言 时间:
2014-05-01 04:46:15
阅读次数:
373
1.stable_sort 和 sort的区别在于 前者作排序可以使原来的"相同"的值在序列中的相对位置不变
如 1 4 6 7 4' (4 和 4'值相等,加上' 表示是2个元素)
那么stable_sort能保证排序完 4 仍然在4' 前 也就是输出1 4 4' 6 7;但是sort 没有这个功能,算法不能保证这一点
2.在标准算法中的一部分算法 如果这个算法默认使用的是
...
分类:
其他好文 时间:
2014-04-29 13:45:20
阅读次数:
273
参考博客:http://blog.kuoe0.tw/posts/2014/01/31/install-gnu-gcc-on-os-x-and-use-the-header-bits-stdcplusplus-h-and-policy-based-data-structure
做CF看见别人用这个函数,然后就能直接用vector,set,string那些函数了,摸不着头脑,感觉特神奇就百度了一下,...
分类:
编程语言 时间:
2014-04-29 13:32:22
阅读次数:
433
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
...
分类:
其他好文 时间:
2014-04-29 13:28:21
阅读次数:
398
在sort中因为默认是升序的,所以一般我们需要降序的时候就……了。
以前我在CF上看到有人用sort的数组降序方法,快速简单,然后刚才写425A - Sereja and Swaps题的时候又看到别人vector的降序方法,以前学习的时候怎么不知道呢,哈哈……虽然CF没多大建树,不过确实看到好多大神的编程方法以及优化方法,实在是很有用啊!
很多时候不是我们不懂,而是我们不会优化,对系统的函数用...
分类:
其他好文 时间:
2014-04-29 13:16:21
阅读次数:
322
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
...
分类:
其他好文 时间:
2014-04-29 13:13:21
阅读次数:
309
利用内存chunk充当数据buffer的vector的实现,和STL vector 有接口操作性能比较...
分类:
其他好文 时间:
2014-04-29 13:11:20
阅读次数:
318