题目链接

\(Description\)

  有一张\(n\)个点的完全图,从\(0\)到\(n-1\)标号,每两点\(i,j\)间的边权为\(i\oplus j\)。求其最小生成树边权之和。

\(Solution\)

  为方便,以下点从\(0\)到\(n\)编号。

  每个点\(x\)应和\(x\oplus lowbit(x)\)相连,边权为\(lowbit(x)\)(\(lowbit(x)\)会和\(0\)相连,所以一定能构成树),所以答案为\(\sum_{i=1}^nlb(i)\)。

  继续优化。注意到\(lb(i)\)一定是某个2次幂,所以令\(f(i)\)表示\(1\leq x\leq n\)且满足\(lb(x)=i\)的\(x\)的个数,则答案为\(\sum_{i=1}^nf(i)\times i\ (f(i)>0)=\sum_{i=0}^{\lfloor\log n\rfloor}f(2^i)\times 2^i\)

  \(f(i)\)显然可以用数位DP算,但是太麻烦了。。

  一些满足\(lb(i)=x\)的数,它们间隔至少是\(2x\)。比如\(x=(100)_2\),则\(i=100,1100,10100...\)(相差\(1000\))。所以\(f(x)=\lfloor\frac{n-x}{2x}\rfloor+1\ (1\leq x\leq n,x=2^y)\)。


  还有DP求\(\sum_{i=1}^nlb(i)\)的做法,好长啊...先不看了。


#include <cstdio>

int main()
{
long long n,res=0;
scanf("%I64d",&n); --n;
for(long long x=1; x<=n; x<<=1)
res+=x*((n-x)/(x<<1)+1);
printf("%I64d\n",res); return 0;
}

Codeforces.959E.Mahmoud and Ehab and the xor-MST(思路)的更多相关文章

  1. CodeForces 959E Mahmoud and Ehab and the xor-MST (MST+找规律)

    <题目链接> 题目大意: 给定一个数n,代表有一个0~n-1的完全图,该图中所有边的边权为两端点的异或值,求这个图的MST的值. 解题分析: 数据较大,$10^{12}$个点的完全图,然后 ...

  2. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  3. CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】

    <题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...

  4. Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))

    题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...

  5. CodeForces - 862C Mahmoud and Ehab and the xor(构造)

    题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...

  6. Coderfroces 862 C. Mahmoud and Ehab and the xor

    C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...

  7. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  8. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  9. Codeforces 862A Mahmoud and Ehab and the MEX

    传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...

随机推荐

  1. OpenStack API部分高可用配置(一)

    一.概况与原理  SHAPE  \* MERGEFORMAT 1)所需要的配置组件有:pacemaker+corosync+HAProxy 2)主要原理:HAProxy作为负载均衡器,将对openst ...

  2. DNA序列编码中Hairpin的定义和计算

    DNA序列编码中Hairpin的定义和计算 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 [1] 张凯. DNA计算核酸编码优化及算法设计[D]. 2008. [2] Shin, ...

  3. Parquet 格式文件

    Apache Parquet是Hadoop生态圈中一种新型列式存储格式,它可以兼容Hadoop生态圈中大多数计算框架(Hadoop.Spark等),被多种查询引擎支持(Hive.Impala.Dril ...

  4. Jenkins mac pkg安装 后默认配置文件/启动路径

    自启动文件路径 /Library/LaunchDaemons/org.jenkins-ci.plist jenkins.war 执行文件路径 /Applications/Jenkins/jenkins ...

  5. Javascript - Vue - vue对象的生命周期

    vue对象的生命周期 从vue的创建到销毁会经过一系列的事件,这是vue对象的生命周期. 创建期间的生命周期函数 <div id="box">    <h3 id ...

  6. 001_docker-compose构建elk环境

    由于打算给同事分享elk相关的东西,搭建配置elk环境太麻烦了,于是想到了docker.docker官方提供了docker-compose编排工具,elk集群一键就可以搞定,真是兴奋.好了下面咱们开始 ...

  7. jQuery-介绍

    一:什么是jQuery jQuery 是一个 JavaScript 库. 二:安装 http://jquery.com/download/ http://jquery.cuishifeng.cn/ j ...

  8. .net4.0切换2.0时,SplitContainer”的对象强制转换为类型

    问 题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Windo ...

  9. Coursera台大机器学习技法课程笔记13-Deep Learning

    深度学习面临的问题和现在解决的办法: 简要来说,分两步使用DL:初始化时一层一层的选择权重,而后再进行训练: 那么怎么做pre-training,即怎么选择权重呢?好的权重能够不改变原有资料的信息,即 ...

  10. 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies

    题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...