第一反应是打表找规律……(写了个prim)但是太菜了没找到 于是开始怀疑是不是我的表错了,又写了一个克鲁斯卡尔,然后结果是一样的……(捂脸)
后来从克鲁斯卡尔的算法上发现了一点东西,发现只有2的幂次长度的边才会对答案产生贡献。假设有n个点,那么就相当于把n - 1的点连入MST,打表找规律可得一个二进位位权值的边会把当前一半的点连入MST,于是水过

Code:

#include <cstdio>
using namespace std;
typedef long long ll; ll n, ans = , base = ; int main() {
scanf("%lld", &n);
for(; n > ; ) {
ans += base * (n >> );
base <<= ;
n -= (n >> );
}
printf("%lld\n", ans);
return ;
}

CF 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. 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 ...

  4. CF 862A Mahmoud and Ehab and the MEX【数组操作】

    A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. 【构造】【分类讨论】Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

    题意:给你n,x,均不超过10^5,让你构造一个无重复元素的n个元素的非负整数集合(每个元素不超过10^6),使得它们的Xor和恰好为x. 如果x不为0: 随便在x里面找一个非零位,然后固定该位为0, ...

  6. codeforces 862 C. Mahmoud and Ehab and the xor(构造)

    题目链接:http://codeforces.com/contest/862/problem/C 题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了 由于数据x只有1e5,但是要求是 ...

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

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

  8. Codeforces.959E.Mahmoud and Ehab and the xor-MST(思路)

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

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

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

随机推荐

  1. winform中DataGridView使用DataGridViewCheckBoxColumn实现RadioBox单选功能

    private void dgvMaterial_CellContentClick(object sender, DataGridViewCellEventArgs e) { ; i < dgv ...

  2. golang的项目结构 相关知识

    ### 项目结构 ``` ├── bin │   ├── login │   └── main ├── pkg │   └── darwin_amd64 │   └── login │   └── a ...

  3. k-means算法的优缺点以及改进

    大家接触的第一个聚类方法,十有八九都是K-means聚类啦.该算法十分容易理解,也很容易实现.其实几乎所有的机器学习和数据挖掘算法都有其优点和缺点.那么K-means的缺点是什么呢? 总结为下: (1 ...

  4. Til the Cows Come Home (最短路模板题)

    个人心得:模板题,不过还是找到了很多问题,真的是头痛,为什么用dijkstra算法book[1]=1就错了..... 纠结中.... Bessie is out in the field and wa ...

  5. ACM学习历程—Hihocoder 1291 Building in Sandbox(dfs && 离线 && 并查集)

    http://hihocoder.com/problemset/problem/1291 前几天比较忙,这次来补一下微软笔试的最后一题,这题是这次微软笔试的第四题,过的人比较少,我当时在调试B题,没时 ...

  6. Azure VMSS ---- PowerShell创建自定义镜像的VMSS集群

    前面一篇文章介绍了如何用PowerShell创建标准镜像的VMSS集群.http://www.cnblogs.com/hengwei/p/7391178.html 本文将介绍,如何用PowerShel ...

  7. Maven Build错误。

    错误: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal ...

  8. Nunit 2.6 无法调试.Net Framework 4.0

    <configuration> <!-- The GUI only runs under .NET 2.0 or higher. The useLegacyV2RuntimeActi ...

  9. java代码包装类----------Integer

    总结:我的笔试挂了..基础的继承不懂不会.我不知道到底是哪里的问题. 要好好反思 package com.da.ima2; public class jrfk { // int整型不能直接转化为Int ...

  10. js页面埋点

    页面埋点的作用,其实就是用于流量分析.而流量的意思,包含了很多:页面浏览数(PV).独立访问者数量(UV).IP.页面停留时间.页面操作时间.页面访问次数.按钮点击次数.文件下载次数等.而流量分析又有 ...