Link:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44513511");}
Exercises
Can be stacked with:
Actually it's just a function, not a data structure, its data structure is just "heap"?
Can a random heap be counted as one?
Two heap merges, the contrast size determines who is the father, and then the inferior and gifted sub-recursive comparison, until the end is empty (can not also no longer compare), to meet the normal insertion can guarantee the nature of the second fork stop.
Code:
Can be randomly stacked (randomly attached to a child)
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1001000#define INF 0x3f3f3f3fusing namespace STD;structmerge_heap{intson[n][2],val[n];BOOLBe_killed[n];intFa[n];intFindintx) {returnFa[x]==x?x:fa[x]=find (Fa[x]);}voidInitintN) {val[0]=inf; for(intI=1; i<=n;i++) {scanf("%d", &val[i]); Fa[i]=i; } }intMergeintXintY//Kenggen randomly available and stacked{if(Val[x]>val[y]) swap (x, y);if((x&&y) = =0)returnXintK=rand () &1; Son[x][k]=merge (Son[x][k],y);returnX }voidKill () {intXscanf("%d", &x);if(Be_killed[x]) {puts("0");return; } x=find (x); be_killed[x]=1;printf("%d\n", Val[x]);intK=merge (son[x][0],son[x][1]);if(k) fa[x]=fa[son[x][0]]=fa[son[x][1]]=k; }voidBattle () {intx, y;scanf("%d%d", &x,&y);if(be_killed[x]| | Be_killed[y])return;if(Find (x) ==find (y))return; Fa[fa[x]]=fa[fa[y]]=merge (Fa[x],fa[y]); }}heap;intN,m;Charopt[5];intMain () {//Freopen ("Test.in", "R", stdin);Srand252503);intI,k;scanf("%d", &n); Heap.init (n); for(scanf("%d", &m); m--;) {scanf('%s ', opt);if(opt[0]==' K ') Heap.kill ();ElseHeap.battle (); }return 0;}
"BZOJ1455" Roma games can be stacked