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的 ...
随机推荐
- JavaScript浏览器对象模型(BOM)之location对象
一.概述: location 是 BOM 对象之一,它提供了与当前窗口中加载的文档有关的信息,还提供了一些导航功能. 事实上,location 对象是 window 对象的属性,也是 document ...
- 随手练——大量级阶乘 - HDU-2674 N!Again
N!Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- EF和linq to sql 关系
LINQ to SQL 允许你用任何类来代表数据库中的数据.表.同样的,EF也允许你用任何类来代表苏据库中的数据.表. 所不同的的地方是Linq to sql 用这些被修饰过的类直接同数据库打交道,存 ...
- Markdown语法初体验
前言 由于把博客主题样式换了,所以改用Markdown语法,让代码看起来更加舒服一些. 照葫芦画瓢 这里是H1标题(===) 这里是H2标题(---) 使用一个#号 使用两个#号 使用三个#号 引用 ...
- http_post_data发送数据的获取方式
private function http_get_data($url){ $ch = curl_init($url) ; curl_setopt($ch, CURLOPT_RETURNTRANSFE ...
- java动态代理的基本思想以及简单的实现
代理模式 本人参考于代理模式及Java实现动态代理 不作为商业用途,只是借鉴于其思路.侵权即删. 原理:给某个对象提供一个代理对象,并且由代理对象控制原对象的访问,即不直接操控原对象,而是通过代理对 ...
- Content Editor Webpart(三)使用JSOM
JSOM是SharePoint 提供的一种clientAPI.开发者仅仅须要使用Javescript.就能够实现和SharePoint的交互.很方便. 首先依照 (Content Editor Web ...
- SpringMVC转发页面405错误
需要在该方法前加上:@ResponseBody注解 加上这个注解后可能在转发页面的时候出现问题,则需要在方法的参数中增加HttpServletRequest 和HttpServletResponse参 ...
- macOS:按钮类型
for (int i = 0; i < 10; i++) { for (int j = 1; j < 16; j++) { NSButton *btn = [[NSButton alloc ...
- Angular4 扫雷小游戏
扫雷小游戏,可以升级过关,难度随关卡增加.但是有很明显的bug,以后有时间会继续优化! HTML: <div class="mainContent"> <div ...