头文件
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define ll long long
#define il inline
#define oo (2147413647)
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scc(x, y) scanf("%d%d",&x,&y)
#define sccc(x, y, z) scanf("%d%d%d",&x,&y,&z)
#define p(x) printf("%d\n",x)
const int maxn = 1e5 + 6;
小技巧
1. scanf读入
- 若读入成功,则返回读入的个数
- 若读入失败,则返回EOF(-1)
可通过下面代码来循环读入
int n;
while(~scanf("%d",&n))
while(scanf("%d",&n)!=-1)
读入字符
//scanf读入字符会将'\n' 空格一块读进去
scanf("%c",&c)
- 可以先getchar()读入没用的空格
- scanf读取char之前,用fflush(stdin)空输入缓冲区,使其为空
重写比较运算
struct cmp {
bool operator()(HuffmanTreeNode *h1, HuffmanTreeNode *h2) {
return h1->weight > h2->weight;
}
};
# 最小堆
priority_queue<HuffmanTreeNode *, vector<HuffmanTreeNode *>, cmp> q;
Comments | 0 条评论