"BZOJ1455" Roma games can be stacked

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.