CF 959 E. Mahmoud and Ehab and the xor-MST
E. Mahmoud and Ehab and the xor-MST
https://codeforces.com/contest/959/problem/E
分析:
每个点x应该和x ^ lowbit(x)连边,那么现在就是求$\sum_{i=1}^{n}lowbit(i)$,然后打表找规律。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} int main() {
LL n, res = ;
cin >> n; n--;
for (LL x = ; x <= n; x <<= )
res += ((n - x) / (x + x) + ) * x;
cout << res;
return ;
}
CF 959 E. Mahmoud and Ehab and the xor-MST的更多相关文章
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- 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 959 F. Mahmoud and Ehab and yet another xor task
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \ ...
- Codeforces 959 D Mahmoud and Ehab and another array construction task
Discription Mahmoud has an array a consisting of n integers. He asked Ehab to find another arrayb of ...
- Codeforces 959 E Mahmoud and Ehab and the xor-MST
Discription Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him ...
- 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(构造)【异或】
<题目链接> 题目大意: 给出n.m,现在需要你输出任意n个不相同的数(n,m<1e5),使他们的异或结果为m,如果不存在n个不相同的数异或结果为m,则输出"NO" ...
- 【构造】【分类讨论】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, ...
- 【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor
[链接]h在这里写链接 [题意] 让你组成一个n个数的集合,使得这n个数的异或和为x; x<=1e5 每个数最大1e6; [题解] 1e5<=2^17<=2^18<=1e6的 ...
随机推荐
- 【[SDOI2014]数表】
求 \[\sum_{i=1}^N\sum_{j=1}^Mσ(gcd(i,j))[σ(gcd(i,j))<=a]\] \(σ\)表示约数和函数 感觉非常难求的样子 先把套路搞出来 \[f(n)=\ ...
- P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat…
题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...
- G、CSL 的训练计划【BFS 贪心】(“新智认知”杯上海高校程序设计竞赛暨第十七届上海大学程序设计春季联赛)
题目传送门:https://ac.nowcoder.com/acm/contest/551/G 链接:https://ac.nowcoder.com/acm/contest/551/G来源:牛客网 题 ...
- 10、Web Service-IDEA-jaxrs 整合spring
1.服务端的开发 1.web项目目录 2.pom <?xml version="1.0" encoding="UTF-8"?> <projec ...
- 1、RabbitMQ入门
RabbitMQ 可以参考官网进行学习! 开发语言:Erlang – 面向并发的编程语言. AMQP:是消息队列的一个协议. mysql 是 java 写的吗?不是 那么 java 能不能访问?可以, ...
- vlc-android native调试配置
1, 按照官网给出的链接,git clone代码,配置好android sdk,ndk...后运行compile.sh; 2, 出现一个protobuf相关的问题(貌似要求protobuf3),自己去 ...
- 阅读AuTO利用深度强化学习自动优化数据中心流量工程(一)
目录 问题 解决方法 模型选择 框架构建 Sigcomm'18 AuTO: Scaling Deep Reinforcement Learning for Datacenter-Scale Autom ...
- 不会发布npm包?进来看看?
前言 npm(Node Package Manager),一个Node的包管理器,平时我们常用的公共模块(插件)或者叫做包大多都放在上面,所以接下来要封装的插件,我们就简单称它为npm包,本文从就从这 ...
- java环境变量配置(win7)
JDK1.8 1.单击“计算机-属性-高级系统设置”,单击“环境变量”.在“系统变量”栏下单击“新建”,创建新的系统环境变量. 2. (1)新建->变量名"JAVA_HOME&quo ...
- #leetcode刷题之路17-电话号码的字母组合
给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合.给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例:输入:"23"输出:["a ...