摘要:
标准库里的count_if可以统计容器中满足特定条件的元素的个数。例如要统计一个整数vector——ivec中正数的个数,可以先写一个返回类型为bool,含有一个int参数的条件函数:bool pred(int val)...{return val>0;} 之后可以用count_if(ivec.begin(),ivec.end(),pred)计算出正整数的个数。但这个方法有一个明显的缺陷:如果要统计大于10的个数、大于100的个数……就要写很多个类似的函数,能不能进一步抽象?如果能像这样调用count_if:count_if(ivec.begin(),ivec.end,pred(n)), 阅读全文
posted @ 2013-04-20 17:56
PegasusWang
阅读(1840)
评论(0)
推荐(0)
摘要:
这是Titan Ruins系列第一道题,以后慢慢更新。赤裸裸滴阅读理解题,大意就是找到三个连在一起的数,使其之和最大,输出的第一个数是这三个数的和,第二个数是中间那个数所在的位置。水题一道,很简单。 1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 int main() 5 { 6 int n; 7 cin >> n; 8 int *a = new int[n+1]; 9 for (int i = 1; i <= n; ++i)10 cin >> a[i]; 阅读全文
posted @ 2013-04-20 17:10
PegasusWang
阅读(458)
评论(0)
推荐(0)
摘要:
第一次写这种题,参考一下网上的代码。 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <queue> 5 int dir[][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}}; //四个方向 6 int n, m; 7 const int MAXN = 105; 8 struct Node 9 {10 int x, y, time;11 friend bool operator<(Node a, Node b) //重载 阅读全文
posted @ 2013-04-20 15:04
PegasusWang
阅读(177)
评论(0)
推荐(0)
摘要:
今天又重新回顾了一下忘得差不多的并查集:下边是转的,再加上一道hdu的并查集入门题。文章作者:yx_th000文章来源:Cherish_yimi(http://www.cnblogs.com/cherish_yimi/) 转载请注明,谢谢合作。 [本文新址:http://www.ahathinking.com/archives/10.html]昨天和今天学习了并查集和trie树,并练习了三道入门题目,理解更为深刻,觉得有必要总结一下,这其中的内容定义之类的是取自网络,操作的说明解释及程序的注释部分为个人理解。并查集学习:l并查集:(union-find sets)一种简单的用途广泛的集合. 并 阅读全文
posted @ 2013-04-20 00:02
PegasusWang
阅读(598)
评论(0)
推荐(1)
浙公网安备 33010602011771号