题意:
给出一个有权树,求树上两点路径的最大异或和;
n
题解:
考虑异或的性质,如果任选一点为根,处理出所有点的异或深度;
那么将两点的深度异或起来,LCA到根的路径就异或了两次相当于没有;
所以异或距离就是两点异或深度的异或和,问题就转化成了从n个数中选两个数使异或和最大;
这个经典问题就可以把数字按位存进01trie树,从高位到低位贪心求解;
复杂度O(31n);
...
分类:
其他好文 时间:
2015-07-25 09:34:21
阅读次数:
109
//
// main.m
// 从文件中读取内容
#import
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString * path = @"/Users/ms/Desktop/hello";
NSError * error;
NSString...
分类:
其他好文 时间:
2015-07-25 09:31:50
阅读次数:
111
#import
//写入文件
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString * str = @"你是一只小狗 ";
//创建路径
NSString * path =@"/Users/ms/Desktop/hello/my.txt";
...
分类:
其他好文 时间:
2015-07-25 09:31:41
阅读次数:
126
Given an absolute path for a file (Unix-style), simplify it.
For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"
click to show corner cases.
Corner Cases:
Did ...
分类:
其他好文 时间:
2015-07-25 07:11:54
阅读次数:
196
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which rep...
分类:
其他好文 时间:
2015-07-24 23:54:38
阅读次数:
107
Prime PathTime Limit:1000MSMemory Limit:65536KTotal Submissions:13813Accepted:7796DescriptionThe ministers of the cabinet were quite upset by the mess...
分类:
其他好文 时间:
2015-07-24 22:30:38
阅读次数:
120
string path = "C:\\Users\\aaa\\Desktop\\aa.xls"; string conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + path + ";Extended Pro...
分类:
数据库 时间:
2015-07-24 20:16:05
阅读次数:
122
下载的的mysql有两个版本:一种是.msi,可以直接安装,之后在services.msc中启动服务就行了; 另一种是需要配置的,步骤如下: 1.把文件放到自己想要的地方,类似程序安装目录 2.可以把目录添加到环境变量Path中,方便命令的使用 (可能重启后才生效) 3.修改my-default-....
分类:
数据库 时间:
2015-07-24 20:06:32
阅读次数:
132
which-asvnsudorm/usr/bin/svnblewinstallsvnbrewlink--overwritesubversionecho‘exportPATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"‘>>~/.bash_profilesource~/.bash_profilecat~/.bash_profile
分类:
系统相关 时间:
2015-07-24 18:51:45
阅读次数:
662
#!/bin/shdir_path="/vol/project/log/test/"for year in {2012..2013}do #echo "$year" cd $dir_path mkdir $year for month in {1..12} do ...
分类:
系统相关 时间:
2015-07-24 18:07:50
阅读次数:
190