"Pre-Test Review _ various templates of the supplement"

Source: Internet
Author: User

Well, the exam did not send the article, after the test sent.

I can't sort them out very well. There are some templates that you can put in here if you can't classify them.

One or two points answer (put another one)

 while (l<=R)    {        int mid= (l+r) >>1;         if (Judge (mid)) l=mid+1;         Else r=mid-1;    }    cout<<l;

Second, fast power

int ksm (int x,int y)//x^y{    int t=1, k=y , tmp=x;      while (k)    {        if (k%2) t=t*tmp;        K>>=1;        TMP=tmp*tmp;    }     return t;}

Third, merge (for reverse order)

voidMegesort (intLintR) {    if(L==R)return ; intMid= (l+r) >>1;    Megesort (L,mid); Megesort (Mid+1, R); intI=l,j=mid+1; intri[ the],id=l; Memset (RI,0,sizeof(RI));  while(i<=mid&&j<=r) {if(A[i]<=a[j]) {//<=ri[id]=a[i];id++;i++; }        Else{Ri[id]=a[j];id++;j++; Ans+=mid-i+1; }    }     while(i<=mid) {Ri[id]=a[i];id++;i++; }     while(j<=R) {Ri[id]=a[j];id++;j++; }     for(inti=l;i<=r;i++) A[i]=ri[i];}

Iv. Heap (sort, handwritten priority_queue)

1. Adding elements

void pushup (int x)//{    int  now,ne;    hep[++siz]=x;    now =siz;      while (now>1) {        ne=now/2;         if return ; //          Swap (Hep[now],hep[ne]);        now =ne;     }}

2. Remove the top element of the heap

intPushdown ()//fetch heap TOP element tmp{    inttmp=hep[1]; hep[1]=Hep[siz]; Siz--; intnow=1, NE;  while(now*2<=siz) {//move the current bit down to the appropriate location and return to the TMPne=now*2; if(ne<siz&&hep[ne+1]//Put the left and right smaller in now        if(Hep[now]<=hep[ne])returntmp;         Swap (Hep[now],hep[ne]); now=NE; }    returntmp//*** }

Five or two points matching

BOOLFindway (intu) {     for(intI=he[u];i;i=Ne[i])if(!Check[to[i]]) {Check[to[i]]=true; if(match[to[i]]==-1|| Findway (Match[to[i]))//**{Match[to[i]]=u;//            return true; }    }    return false;}intHungary ()//km Hungarian algorithm{memset (match,-1,sizeof(match));  for(intI=1; i<=n;i++) {memset (check,0,sizeof(check)); if(Findway (i)) ans++; }    returnans;}

Vi. Tarjan (strongly connected components of a forward graph)

voidTarjan (intu) {Dfn[u]=low[u]=++idx; stak[++instak]=u; inch[u]=true;  for(intI=he[u];i;i=Ne[u]) {        if(!Dfn[to[i]])            {Tarjan (to[i]); Low[u]=min (low[to[i]],low[u]); }        if(inch[to[i]]&&dfn[to[i]]<Low[u]) Low[u]=Dfn[to[i]]; }    if(dfn[u]==Low[u]) {ans++; intj=Stak[instak];  while(j!=u) {J=stak[--Instak]; inch[j]=false; }    }}

"Pre-Test Review _ various templates of the supplement"

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.