Code Monkey home page Code Monkey logo

mynotes's Introduction

MyNotes

笔记的话现在在个人博客发表,就不会再在这个仓库更新啦~

个人博客https://patrick.cc

mynotes's People

Contributors

patrickctyyx avatar

Watchers

 avatar  avatar

mynotes's Issues

啊哈, 关于进制运算巧妙运用莫过于lca倍增算法了

树上两点最近公共祖先问题, 可以看一下这个人的博客http://www.cnblogs.com/FuTaimeng/p/5655616.html, 只需要注意一行就行

int lca(int a,int b){
    if(d[a]>d[b])swap(a,b); //b在下面 
    int f=d[b]-d[a];//f是高度差
    for(int i=0;(1<<i)<=f;i++){//(1<<i)&f找到f化为2进制后1的位置,移动到相应的位置
        if((1<<i)&f)b=p[b][i];//比如f=5(101),先移动2^0祖先,然后再移动2^2祖先
    }
    if(a!=b){
        for(int i=(int)log2(N);i>=0;i--){
            if(p[a][i]!=p[b][i]){//从最大祖先开始,判断a,b祖先,是否相同
                a=p[a][i]; b=p[b][i];//如不相同,a b同时向上移动2^j
            }
        }
        a=p[a][0];//这时a的father就是LCA
    }
    return a;
}

中间一行

if((1<<i)&f)b=p[b][i];

(1<<i)&x 表示 x二进制的第i位是否为1

进阶的话NOIP2013货车运输的最优解, 最大生成树方法中那个比较好. 比如这个人写的博客http://hzwer.com/1344.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.