标题效果:有一个宠物收容所。目前还没有被采纳的宠物或谁想要领养宠物,每个宠物有个性值,大家谁想要领养宠物具有理想人格值。每一刻,宠物收容所只是为了有谁想要领养宠物或宠物的人。
当领走宠物,将有一定程度的不愉快。最低要求是不舒服程度。
注意极大值不能开太大。会re
CODE:
#include#include#include#include#defineINF0x3f3f3f3fusingnamespacestd;structComplex{intval,random,cnt,size;Complex*son[2];Complex(){son[0]=son[1]=NULL;random=rand();cnt=size=1;}voidMaintain(){size=cnt;if(son[0]!=NULL)size+=son[0]->size;if(son[1]!=NULL)size+=son[1]->size;}intCompare(intx){if(x==val)return-1;returnx>val;}}*root;intcnt,ans;inttotal;intflag;inlinevoidRotate(Complex*&a,booldir);voidInsert(Complex*&a,intx);voidDelete(Complex*&a,intx);intFindSucc(Complex*a,intx);intFindPred(Complex*a,intx);intmain(){cin>>cnt;for(intx,i=1;i<=cnt;++i){scanf("%d%d",&flag,&x);if(total>0){if(flag)Insert(root,x),total++;else{intpred=FindPred(root,x);intsucc=FindSucc(root,x);intwill_delete=(x-pred<=succ-x)