随笔分类 - STL
摘要:在c++编程中,用到迭代器的时候,往往不知道如何删除当前迭代器指向的元素。 erase函数: 返回下一个迭代器。 只使用vector的erase函数,记住,该函数是迭代器失效,返回下一个迭代器。 看下面的一个程序,删除值为4和7的元素,为什么只删除了4? 没有删除7,为什么? 上面的程序基本上属于弱
阅读全文
摘要:关于全排列,使用 C++ 的同学有一个福利,在 <algorithm> 库里面有一个生成全排列的next_permutation函数,可以直接调用。调用方法如下 1 #include <algorithm> 2 #include <stdio.h> 3 int main() { 4 int a[]
阅读全文
摘要:给定一个n,输入n个数,输出这n个数中出现频率最多的数的值及出现频率。频率相同时,取较大值。 这里用map可以轻松解决。但是wa了无数次。。。。。 原来是初值设置错了。0x3fffffff可以做为正数的INF,但是-0x3fffffff不行,,,,-0xfffffff则是1,不明觉吊。 改了初始的k
阅读全文
摘要:Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of
阅读全文
摘要:A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run o
阅读全文
摘要:看病要排队 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status 看病要排队 Submit Status Description 看病要排队这个是地球人都知道的常识。 不过经过细心的006
阅读全文
摘要:#include <iostream> #include <queue> using namespace std; int main(){ priority_queue<int> q; for( int i= 0; i< 10; ++i ) q.push( rand() ); while( !q.e
阅读全文
摘要:转载自:http://blog.csdn.net/phoebin/article/details/3864590 介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作。本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each(
阅读全文