博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 959 E. Mahmoud and Ehab and the xor-MST
阅读量:4552 次
发布时间:2019-06-08

本文共 767 字,大约阅读时间需要 2 分钟。

E. Mahmoud and Ehab and the xor-MST

分析:

  每个点x应该和x ^ lowbit(x)连边,那么现在就是求$\sum_{i=1}^{n}lowbit(i)$,然后打表找规律。

代码:

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 using namespace std;12 typedef long long LL;13 14 inline int read() {15 int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;16 for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;17 }18 19 int main() {20 LL n, res = 0;21 cin >> n; n--;22 for (LL x = 1; x <= n; x <<= 1) 23 res += ((n - x) / (x + x) + 1) * x;24 cout << res;25 return 0;26 }

 

转载于:https://www.cnblogs.com/mjtcn/p/10070783.html

你可能感兴趣的文章
node的consoidate的插件统一
查看>>
POj2387——Til the Cows Come Home——————【最短路】
查看>>
EPLAN标题页及图框的设计
查看>>
坐标下降法(coordinate descent method)求解LASSO的推导
查看>>
读后疑问
查看>>
实力为王 八年DBA经验谈
查看>>
More Effective C++ (静态绑定与动态类型)
查看>>
shell脚本57问
查看>>
2-sat 问题 【例题 Flags(2-sat+线段树优化建图)】
查看>>
ext3.2 右击动态添加node的treepanel
查看>>
Database links
查看>>
GitHub 优秀的 Android 开源项目
查看>>
uva10158
查看>>
深入浅出Mybatis-与Spring集成
查看>>
跨域访问-需要设置HTTP响应标头
查看>>
1035 插入与归并(25 分)
查看>>
STL中排序函数的用法(Qsort,Sort,Stable_sort,Partial_sort,List::sort)
查看>>
数组去重
查看>>
如何解决php 生成验证码图片不显示问题
查看>>
PHP,javascript实现大文件上传
查看>>