笔记的话现在在个人博客发表,就不会再在这个仓库更新啦~
patrickctyyx / mynotes Goto Github PK
View Code? Open in Web Editor NEWSome notes
Some notes
笔记的话现在在个人博客发表,就不会再在这个仓库更新啦~
树上两点最近公共祖先问题, 可以看一下这个人的博客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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.