zoukankan      html  css  js  c++  java
  • dijkstra最短路手写堆

    真的只想说一点:细节!!!!!!delet的top--在哪写,还有down 里面的while(s<=top) 不要写成<=n!!!!!!!   s<top不要写成 s<n  
    我调了一个上午while(s<top)调了将近两个小时,结果忘改后边那个,,又改了一个小时,心态炸了,怎么老犯sd错误
    heap是权值,pn是head[x]中的x也就是点编号
    inline void swp(int &x,int &y){x^=y,y^=x,x^=y;} inline void up(int p) { while(p>1){ if(heap[p]<heap[p>>1]) swp(heap[p],heap[p>>1]),swp(pn[p],pn[p>>1]); else break; p>>=1; } } inline void down(int p){ int s=(p<<1); while(s<=top){ if(s<top&&heap[s]>heap[s+1]) ++s; if(heap[s]<heap[p]) {swp(heap[s],heap[p]),swp(pn[s],pn[p]);} else break; p=s,s=(p<<1); } } inline void insert(int x,int y){ heap[++top]=x,pn[top]=y,up(top); } inline void delet(){ heap[1]=heap[top],pn[1]=pn[top--];down(1); } inline void djs() { int x; dis[num[stx][sty]]=0; insert(0,num[stx][sty]); while(top) { x=pn[1],delet(); if(mark[x]) continue; mark[x]=1; for(register int i=head[x];i;i=line[i].next) { int v=line[i].to; if(dis[v]>dis[x]+line[i].w) { dis[v]=dis[x]+line[i].w; insert(dis[v],v); } } } }
  • 相关阅读:
    ASP.net:Literal控件用法
    css如何自动换行对于div,p等块级元素(转)
    java ftp操作类
    java文件操作类
    geoserver图层显示
    java csv读取
    geoserver 源码编译(转)
    ArcGIS Engine 空间运算
    ArcMap操作技巧
    geoserver开发资料收集
  • 原文地址:https://www.cnblogs.com/three-D/p/11319481.html
Copyright © 2011-2022 走看看