摘要: 思路:用优先队列 priority_queue,简单两种方式改变队列 的优先级 (默认的是从大到小)#include#include#includeusing namespace std;struct node{ char name[100]; int para; int pri;... 阅读全文
posted @ 2014-08-03 12:00 gongpixin 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 关于priority_queue1,关于STL中的priority_queue:确定用top()查看顶部元素时,该元素是具有最高优先级的一个元素. 调用pop()删除之后,将促使下一个元素进入该位置.2,如同stack和queue,priority_queue是一个基于基本序列容器进行构建的适配器,... 阅读全文
posted @ 2014-08-03 10:59 gongpixin 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 1. while(scanf("%d",&n) )// 错误,会出现 Runtime Error(ACCESS_VIOLATION) while(scanf("%d",&n) !=EOF ) //正确 阅读全文
posted @ 2014-08-01 18:13 gongpixin 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 思路:除以2^k,找到商为奇数的位置,k为层数,有2^(k+1)-1个节点这里直接用位运算,x & -x 就求出 2^k 了。#includeusing namespace std;long lowbit(long x){ return x & -x;}int main(){ long n,x; c... 阅读全文
posted @ 2014-07-31 12:11 gongpixin 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 思路:递归左子树、右子树#include#includeusing namespace std;char preord[30],inord[30];void recover(int preleft,int preright,int inleft,int inright){ int root,left... 阅读全文
posted @ 2014-07-31 10:38 gongpixin 阅读(161) 评论(0) 推荐(0) 编辑
摘要: assert宏的原型定义在中,其作用是如果它的条件返回错误,则终止程序执行,原型定义:#include void assert( int expression ); assert的作用是现计算表达式 expression ,如果其值为假(即为0),那么它先向stderr打印一条出错信息,然后通过调... 阅读全文
posted @ 2014-07-31 10:17 gongpixin 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 思路:一步一步往上走即可#includeusing namespace std;int main(){ int sc; cin>>sc; for(int s=1;s>a>>b; int left=0,right=0; while(1) { if(a>b) { int up=(a-... 阅读全文
posted @ 2014-07-31 09:38 gongpixin 阅读(203) 评论(0) 推荐(0) 编辑
摘要: //思路: 二叉树中X节点的高 = 二叉树中X的父节点的高 + X是第几个儿子#include #includeusing namespace std; string s; int i,n=0,height1,height2; void work(int level1,int level... 阅读全文
posted @ 2014-07-30 21:08 gongpixin 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 思路:直接用并查集,最后找到 0 所在的集合,把 集合中的 人数 输出即可 阅读全文
posted @ 2014-07-30 15:20 gongpixin 阅读(178) 评论(0) 推荐(0) 编辑
摘要: string 中的 length函数 和 size函数 的返回值( 还有 char [ ] 中 测量字符串的strlen 函数)应该是 unsigned int 类型的不可以 和 -1 比较。应尽量避免 unsigned int 类型 和 int类型 数据 的比较 。当unsigned int 类型... 阅读全文
posted @ 2014-07-30 09:41 gongpixin 阅读(1456) 评论(0) 推荐(0) 编辑