随笔分类 -  STL

摘要:multiset 第一次用,太神奇了题意:push a 把a压栈;pop b 把小于等于b的所有元素中最大的元素的出栈,若没有则输出“No Element!”!View Code #include<iostream> #include<stdio.h> #include<set> using namespace std; int main() { multiset<int> st; multiset<int>::iterator it; int n; char op[5]; int tp; while(scanf("%d&q 阅读全文
posted @ 2012-05-25 22:32 枕边梦 阅读(282) 评论(0) 推荐(0)
摘要:网上很多用线段树做的,,好复杂,,,这个是用纯STL做的,map+set转自http://blog.csdn.net/zz_1215/article/details/7318800View Code #include<iostream>#include<vector>#include<algorithm>#include<string>#include<map>#include<set>using namespace std;map<int, set<int> > m;//x映射到一个y坐标的集合m 阅读全文
posted @ 2012-04-15 09:35 枕边梦 阅读(308) 评论(0) 推荐(0)
摘要:题意:纯模拟题,用N个优先队列表示ID为0~N-1的Resource再重载一下操作符即可,剩下的就是模拟了ID好的范围是10000,询问的次数也是10000,里面的hash操作是多余了,自己没有考虑清楚………………View Code #include<iostream>#include<algorithm>#include<queue>#define MAXN 10010using namespace std;struct node{ int pri,num; bool friend operator<(const node a,const node 阅读全文
posted @ 2012-02-26 10:56 枕边梦 阅读(192) 评论(0) 推荐(0)
摘要:hdu3350题意:按照宏定义的规则,计算一个给定的宏定义中‘+’的运算次数。分析:用栈实现的纯模拟的题目View Code #include<iostream>#include<algorithm>#include<stack>#define MAXN 1000+10using namespace std;struct number{ int x,num;};//保存出现过的数,以及该数字执行‘+’的次数stack<number> st;//保存出现过的数字stack<char> oper;//保存操作符char str[MAXN] 阅读全文
posted @ 2012-02-23 12:08 枕边梦 阅读(583) 评论(0) 推荐(0)
摘要:蛮好的题目,练STL,双重Map#include<iostream>#include<map>#include<string>using namespace std;int main(){ int a; cin>>a; while(a--) { map<string,map<string,int> >m; int b,count; cin>>b; string x,y; while(b--) { cin>>x>>y>>count; ... 阅读全文
posted @ 2011-12-19 21:37 枕边梦 阅读(231) 评论(0) 推荐(0)
摘要:hdu 4041 Eliminate Witches!题意:去掉题目背景,给你一个串,转化为一棵树,输出先序遍历节点的顺序;分析:整个串由节点名字,'('、')'、',' 组成,遇到一个括号时,当前左括号是当前括号内节点的父节点,括号内用','隔开的是兄弟节点,整体就是一颗树;若要将该串转化为树,再进行一次DFS的话,我想应该会超时吧。所以第一感觉就是用栈模拟整个串来遍历该树,用队列来保存遍历节点的顺序,用数组应该会更快吧,不过不知道大概会有多大,所以就偷一下懒,直接用队列了。队列是用来保存遍历节点的顺序的,而栈保存的是当前遍历到 阅读全文
posted @ 2011-09-19 14:33 枕边梦 阅读(448) 评论(0) 推荐(0)
摘要:题目大意:在二维平面上,给一些点。有两个操作:给一个d,把所有x为d的点去掉,或把所有y为d的点去掉,问每次去掉的点。我的思路:先将横纵坐标都离散化(大部分时间都花在这个上面吧),然后直接把出现过的点(离散过的点)累计,每次询问之后就可以直接输出了,之后再维护一下,把对应的x或y的累计值 减1==! 很浅显的思路我的代码:600+msView Code #include<iostream>#include<map>using namespace std;map<int,int> mapx;map<int,int> mapy;map<int, 阅读全文
posted @ 2011-09-11 03:01 枕边梦 阅读(358) 评论(0) 推荐(0)
摘要:若输入A 战胜 B时,就让B指向A。最后,指向空的就说明没有人战胜过他。如果这样的人只存在一个,那他就是冠军了。 名字的映射用map实现,出现过的名字用set保存#include <set>#include <map>#include <string>#include <iostream>using namespace std;int main(void){ int n, i, t; string b, e; set <string> s; set <string>::iterator it; map <string 阅读全文
posted @ 2011-09-07 16:26 枕边梦 阅读(198) 评论(0) 推荐(0)
摘要:The Frog's Games 二分枚举答案View Code #include<iostream>#include<algorithm>using namespace std;int L,n,m;int a[500002];int cmp(const void *c ,const void *b ) { return *(int *)c - *(int *)b; } int main(){ while(scanf("%d %d %d",&L,&n,&m)==3) { int maxn=0; for(int i=1; 阅读全文
posted @ 2011-09-04 22:35 枕边梦 阅读(253) 评论(0) 推荐(0)
摘要:擅长排列的小明时间限制:1000 ms | 内存限制:65535 KB 难度:4描述 小明十分聪明,而且十分擅长排列计算。比如给小明一个数字5,他能立刻给出1-5按字典序的全排列,如果你想为难他,在这5个数字中选出几个数字让他继续全排列,那么你就错了,他同样的很擅长。现在需要你写一个程序来验证擅长排列的小明到底对不对。输入 第一行输入整数N(1<N<10)表示多少组测试数据,每组测试数据第一行两个整数 n m (1<n<9,0<m<=n) 输出 在1-n中选取m个字符进行全排列,按字典序全部输出,每种排列占一行,每组数据间不需分界。如样例 样例输入 23 1 阅读全文
posted @ 2011-05-17 10:22 枕边梦 阅读(1618) 评论(0) 推荐(0)
摘要:这道题,呵呵,题目那么长,说到底,是要计算一个数出现重复出现最多的次数题目说,一连串不重复的数,只需要一个所以同一个数重复一次就需要多一个呵呵,用map轻松解决了#include <iostream>#include <map>using namespace std; int n; int main(){ while (scanf("%d", &n) != EOF) { map<int, int> m; map<int, int>::iterator it; int i, a; for (i=0; i<n; i+ 阅读全文
posted @ 2011-05-12 20:26 枕边梦 阅读(238) 评论(0) 推荐(0)
摘要:pku1731还有pku12561731是对stl中的next_permutation算法的基本应用具体用法:http://blog.csdn.net/aipb2008/archive/2008/03/29/2227490.aspx在标准库算法中,next_permutation应用在数列操作上比较广泛.这个函数可以计算一组数据的全排列.但是怎么用,原理如何,我做了简单的剖析.首先查看stl中相关信息.函数原型:template<class BidirectionalIterator> bool next_permutation( BidirectionalIterator _Fi 阅读全文
posted @ 2011-05-10 23:02 枕边梦 阅读(702) 评论(0) 推荐(0)
摘要:STL中的所有算法(70个)参考自:http://www.cppblog.com/mzty/archive/2007/03/14/19819.htmlhttp://hi.baidu.com/dinglinbin/blog/item/887e7c30c12e429ba9018e30.html STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成。要使用 STL中的算法函数必须包含头文件<algorithm>,对于数值算法须包含<numeric>,<functional>中则定义了 阅读全文
posted @ 2011-05-10 22:45 枕边梦 阅读(4784) 评论(0) 推荐(0)