#include
#include
#define onlinejudge
const int maxn = 1000010;
const int INF = 0x3F3F3F3F;
char ch;
int casenum, kNum, cnt, num, heap[maxn];
void shiftdown(int fa, int n)
{
int son, key=heap[fa];
for (; fa<=n>>1; fa=son)
{
son = fa<<1; /* Left_child */
if (son!=n && heap[son+1]
heap[son])
heap[fa] = heap[son];
else
break;
}/* End of For */
heap[fa] = key;
}/* shiftdown */
void InsertHeap(int t)
{
heap[++cnt] = t;
int p = cnt;
while (p!=1 && heap[p>>1]>t)
{
heap[p] = heap[p>>1];
p >>= 1;
}/* End of While */
heap[p] = t;
}/* InsertHeap */
void PopHeadTop(int t)
{
heap[1] = t;
shiftdown(1, cnt);
}/* PopHeadTop */
int main()
{
#ifdef onlinejudge
旧代码 - 手写堆
最新推荐文章于 2022-04-02 11:04:06 发布