摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2527题意:建完树后,判断下除了叶子结点之外的其他结点之和是否大于题目给出的数字。思路:如果了解哈夫曼树,就会知道,它是拿出一串数中两个权值最小的,合成一个新的,再将这个新形成的加入到那个串中,再操作.......这样,就可以用优先队列来模拟建哈夫曼树的过程,从而ac此题。注意:此题有坑,被它弄wa了2次,就是当它有n个a时,也要判断.......例如:45aaaaayes5aaaaaano#include<iostream>#include<queue>using namespace 阅读全文
posted @ 2013-01-12 18:40 紫忆 阅读(1018) 评论(0) 推荐(0) 编辑
摘要: 1、在用树状数组的时候,有些时候写得快了,忘了将数组全部置0//memset(c,0,sizeof(c));2、在做题时,没有完全针对题目设置n值,导致有些题目出错。3、在做成段更新,单点求值的题目时,不怎么熟练。 阅读全文
posted @ 2013-01-12 12:49 紫忆 阅读(172) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/discuss/problem/post/new.php?problemid=4006思路:一开始我是想自己编一个最小堆来实现的,回来想了想,还是直接用优先队列吧。因为要第k大,在一个测试中k值是固定的,所以,我只要保留前k大的数,然后输出最小的那个数就可以了。#include<iostream>#include<queue>using namespace std;struct ss{ friend bool operator<(const ss a,const ss b) { if(a.v>b.v) return 阅读全文
posted @ 2013-01-12 11:58 紫忆 阅读(689) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>using namespace std;typedef struct tree{ tree *l,*r; int num;}tree;tree *creat(int x) //建树{ tree *t=(tree *)malloc(sizeof(tree)); t->l=0; t->r=0; t->num=x; return t;}tree *inster(tree *s,int x) //插入结点{ if(s==NULL) { tree *... 阅读全文
posted @ 2013-01-12 10:12 紫忆 阅读(216) 评论(0) 推荐(0) 编辑