Codeforces.959E.Mahmoud and Ehab and the xor-MST(思路)
\(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(思路)的更多相关文章
- CodeForces 959E Mahmoud and Ehab and the xor-MST (MST+找规律)
<题目链接> 题目大意: 给定一个数n,代表有一个0~n-1的完全图,该图中所有边的边权为两端点的异或值,求这个图的MST的值. 解题分析: 数据较大,$10^{12}$个点的完全图,然后 ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))
题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...
- CodeForces - 862C Mahmoud and Ehab and the xor(构造)
题意:要求构造一个n个数的序列,要求n个数互不相同,且异或结果为x. 分析: 1.因为0 ^ 1 ^ 2 ^ 3 ^ ... ^ (n - 3) ^ (n - 2) ^ (0 ^ 1 ^ 2 ^ 3 ...
- 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 ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- 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 ...
随机推荐
- python---django中模板布局
对于页面大部分一样,我们可以使用模板布局来简化 可以查看tornado中的模板引擎,基本一致 python---tornado模板引擎 对于相同代码部分,我们可以提取出来,放在布局文件layout.p ...
- 2018年11月25日ICPC焦作站参赛总结
可能就这么退役了吧. 对这次ICPC还是比较有信心的,毕竟心态都放平和了. 路途很波折,热身赛还是赶上了. 等到了正赛的时候,开场看出了A题的签到,签到肯定是我来签的,11分钟签完了这道题之后,开始看 ...
- HDU 5528 反演
$f(m)=\sum\limits_{i=1}^{m-1}\sum\limits_{j=1}^{m-1}[(ij,m) \ne m]$,$g(n)=\sum\limits_{m|n}f(m)$,$1 ...
- CSS3 Day1 练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用phpStorm的数据库工具来管理你的数据库
phpStorm是一个功能强大的IDE,不仅对PHP提供了支持,而且对前端HTML.CSS.JavaScript的支持也是非常不错的.此外,phpStorm还集成了很多实用的功能,下面就phpStor ...
- 数据绑定和第一个AngularJS Web应用
<!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="UT ...
- RaspberryPi.1.开机与远程桌面
raspberry 3b+ ------------------------------------------------------------------------------- 写系统 有 ...
- Dream_Spark定制第二课
Spark版本定制第2天:通过案例对SparkStreaming透彻理解之二 本期内容: 1 解密Spark Streaming运行机制 2 解密Spark Streaming架构 一切不能进行实时流 ...
- 【转】SpringMVC Controller 介绍
转自:原文url 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...
- centos:SSH登录时间很慢
vi /etc/ssh/sshd_config GSSAPIAuthentication 改为 no 开启UseDNS,值改为 no service sshd restart