【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
把序列生成的过程看成一颗树
会发现最后形成的是一颗二叉树。
每个二叉树上的节点就对应了序列中的一个数字。
如果我们把每个节点都往下投影的话。
(而且整棵树都是左右对称的。那么每个子树的根节点就是(l+r)/2了
就像是整个序列了。
(中序遍历
则我们可以用线段树求区间和的方法。
现在相当于告诉你1..n这个区间。
然后你要求l..r这个区间的和。
递归求就好。
【代码】
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n,l,r;
LL dfs(LL n,LL L,LL R,LL l,LL r){
LL mid = (l+r)>>1;
LL temp = 0;
if (l==r) return n;
if (L<mid) temp+=dfs(n/2,L,R,l,mid-1);
if (mid<R) temp+=dfs(n/2,L,R,mid+1,r);
if(L<=mid && mid<=R) temp+=n%2;
return temp;
}
int main()
{
cin >> n >> l >> r;
LL tot = 1,x = n;
while (x>1){
tot = tot + 1 + tot;
x>>=1;
}
cout<<dfs(n,l,r,1,tot)<<endl;
return 0;
}
【Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B】 Code For 1的更多相关文章
- 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
打表找规律即可. 1,1,2,2,2,3,3,3,3,4,4,4,4,4... 注意打表的时候,sg值不只与剩下的石子数有关,也和之前取走的方案有关. //#include<cstdio> ...
- 【概率dp】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define ...
- 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...
- 【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
观察一下,将整个过程写出来,会发现形成一棵满二叉树,每一层要么全是0,要么全是1. 输出的顺序是其中序遍历. 每一层的序号形成等差数列,就计算一下就可以出来每一层覆盖到的区间的左右端点. 复杂度O(l ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) D. Jon and Orbs
地址:http://codeforces.com/contest/768/problem/D 题目: D. Jon and Orbs time limit per test 2 seconds mem ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C - Jon Snow and his Favourite Number
地址:http://codeforces.com/contest/768/problem/C 题目: C. Jon Snow and his Favourite Number time limit p ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1
地址:http://codeforces.com/contest/768/problem/B 题目: B. Code For 1 time limit per test 2 seconds memor ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A. Oath of the Night's Watch
地址:http://codeforces.com/problemset/problem/768/A 题目: A. Oath of the Night's Watch time limit per te ...
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined)
C题卡了好久,A掉C题之后看到自己已经排在好后面说实话有点绝望,最后又过了两题,总算稳住了. AC:ABCDE Rank:191 Rating:2156+37->2193 A.Oath of t ...
随机推荐
- JTree知识小点
创建一个新节点 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("新节点"); 被选中的节点 Default ...
- linux下如何查看cpu信息
linux的cpu信息可以从文件中cpuinfo读取. 执行命令: # cat /proc/cpuinfo 我们一般看到的processor是逻辑核. 它的计数是从0开始的,例如这里看到的是31 ...
- Ubuntu 安装wps-office
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50288483 本人的ubuntu系统是 ...
- mysql 全表扫描、全索引扫描、索引覆盖(覆盖索引)
full index scan:全索引扫描,查询时,遍历索引树来获取数据行.如果数据不是密集的会产生随机IO 在执行计划中是Type列,index full table scan:通过读物理表获取数据 ...
- HDU 4324 Contest 3
直接DFS即可 #include <iostream> #include <string.h> #include <algorithm> #include < ...
- QQ在线人数统计图数据解析
转载请注明出处:http://blog.csdn.net/xiaoy_h/article/details/27980851 我相信非常多人一定去过这个地方: http://im.qq.com/onli ...
- MarkDown、Vim双剑合璧
作为一名软件攻城狮(是的,我从来都以攻城狮自居! 我坚信如今的每一天,都在朝攻城狮迈进.虽然被菜鸟的肉身皮囊裹着,我依然还是怀着攻城狮的内心! 我非常讨厌别人喊我程序猿.虽然这是不争的事实!).... ...
- Hadoop 2.2.0和HBase-0.98 安装snappy
1.安装须要的依赖包及软件 须要安装的依赖包有: gcc.c++. autoconf.automake.libtool 须要安装的配套软件有: Java6.Maven 关于上面的依赖包,假设在ubun ...
- 【原创】Zend Framework 2框架之MVC
ZendFramework 2框架之MVC 作者:sys(360电商技术组) 1.前言 Zend Framework 2是zend官方推出的php开源框架,基于php5.3.他全然採用面向对象的代码实 ...
- C/S和B/S交互
近期一直在做C/S的项目,每天都超忙,抽个时间写篇博客,之前一直做C/S项目就是各种窗口.各种控件,拖来拖去,然后点进去写方法,做BS的时候呢,由于一直使用的是mvc,所以就是常常手写代码.或者拖引用 ...