随笔分类 -  STL

STL
摘要:http://acm.zju.edu.cn/onlinejudge/showSubmission.do?submissionId=3568082View Code //确定king只有一个后可以在O(N)解决每次询问const int MM = 331630;const int maxn = 31;typedef long long int64;#define debug puts("wrong"); int N,M,Q;char ss[MM][100];set<pair<int,int> >sbt;map<string,int>mp;m 阅读全文
posted @ 2013-05-08 21:57 zhang1107 阅读(224) 评论(0) 推荐(0)
摘要:map STLView Code //map<vector<int>,int>vis; 可以对一个list进行映射。//类似于map<map<int,int>,int>vis 之类的都是可以做到的,注意键值需要一一对应。//begin() 返回指向map头部的迭代器//clear() 删除所有元素//count() 返回指定元素出现的次数//empty() 如果map为空则返回true//end() 返回指向map末尾的迭代器//erase() 删除一个元素//find() 查找一个元素 //if(vis.find(x)!=vis.end())/ 阅读全文
posted @ 2013-04-29 10:49 zhang1107 阅读(137) 评论(0) 推荐(0)
摘要:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4013记忆化搜索,学到啦用map做映射不用担心数组开多大的问题,还有map<vector<int>,int>vis;可以对一个list进行映射,由于10^9以内的素数因子的组合很少,可以记忆化。View Code //记忆化搜索,学到啦用map做映射不用担心数组开多大的问题,还有map<vector<int>,int>vis;//可以对一个list进行映射,由于10^9以内的素数因子的组合很少,可以记忆化。const int M 阅读全文
posted @ 2013-04-29 10:34 zhang1107 阅读(269) 评论(0) 推荐(0)
摘要:View Code struct Info{ int val,key; bool friend operator<(Info x,Info y) { return x.val>y.val; //定义比较,默认按照val大->小排序 }};multiset<int, greater<int> > sbt;//头文件:#include <set>//multiset<int> sbt; //默认小到大//multiset<int, greater<int> > sbt; //定义大到小//元素键值允许重复 O 阅读全文
posted @ 2013-04-26 16:26 zhang1107 阅读(224) 评论(0) 推荐(0)
摘要:View Code //头文件:#include <algorithm>//O(N!)const int maxn = 1000; int num[maxn];void permut(int n) { //n:元素个数 int i,j,k; sort(num,num+n); //注意排序 do { for(i=0;i<n;i++) printf("%d ",num[i]); printf("\n"); }while(next_permutation(num,num+n));} 阅读全文
posted @ 2013-04-20 13:47 zhang1107 阅读(125) 评论(0) 推荐(0)
摘要:View Code //头文件:#include <queue>struct Tpoint{ int val,dead; //Tpoint(int v,int d):val(v),dead(d) {} bool friend operator<(Tpoint x,Tpoint y) { if(x.val!=y.val) return x.val>y.val; else return x.dead>y.dead; }};//多个key,重载运算符,que.top()保存的是val最小的priority_queue<Tpoint>que; 阅读全文
posted @ 2013-04-17 12:34 zhang1107 阅读(170) 评论(0) 推荐(0)
摘要:http://www.cplusplus.com/reference/cctype/isalnumView Code /* isalnum example *//*Checks whether c is either a decimal digit or an uppercase or lowercase letter.*/#include <stdio.h>#include <cctype>int main (){ int i; char str[]="c3Po..."; i=0; while (isalnum(str[i])) i++; prin 阅读全文
posted @ 2013-03-20 14:09 zhang1107 阅读(170) 评论(0) 推荐(0)
摘要:http://www.cplusplus.com/reference/cassert/View Code /* assert example */#include <stdio.h> /* printf */#include <assert.h> /* assert */void print_number(int* myInt) { assert (myInt!=NULL); printf ("%d\n",*myInt);}int main (){ int a=10; int * b = NULL; int * c = NULL; b=&a; 阅读全文
posted @ 2013-03-20 13:41 zhang1107 阅读(170) 评论(0) 推荐(0)