多校赛3- Solve this interesting problem 分类: 比赛 2015-07-29 21:01 8人阅读 评论(0) 收藏
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
System Crawler (2015-07-28)
Description
Segment Tree is a kind of binary tree, it can be defined as this:
- For each node u in Segment Tree, u has two values: $L_u$ and $R_u$.
- If $L_u = R_u$, u is a leaf node.
- If $L_u \neq R_u$, u has two children x and y,with $L_x = L_u$,$R_x = \lfloor \frac{L_u + R_u }{2}\rfloor$,$L_y = \lfloor \frac{L_u + R_u }{2}\rfloor + 1$,$R_y = R_u$.
Here is an example of segment tree to do range query of sum.
Given two integers L and R, Your task is to find the minimum non-negative n satisfy that: A Segment Tree with root node's value $L_{root} = 0$ and $R_{root} = n$ contains a node u with $L_u = L$ and $R_u = R$.
Input
Each test case contains two integers L and R, as described above.
$0 \leq L \leq R \leq 10^9$
$\frac{L}{R-L+1} \leq 2015$
Output
Sample Input
6 7
10 13
10 11
Sample Output
7
-1
12
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm> using namespace std; const int MAX = int(10e9+10); long long n; void DFS(long long L,long long R)
{
if(n&&R>=n)
{
return ;
}
if(L==0)
{
if(n)
{ n=min(n,R);
}
else
{
n=R;
}
return ;
}
if(L<R-L+1)
{
return ;
}
DFS(2*(L-1)-R,R);
DFS(2*(L-1)+1-R,R);
DFS(L,2*R-L);
DFS(L,2*R+1-L);
} int main()
{
long long L,R;
while(~scanf("%I64d %I64d",&L,&R))
{
n=0;
DFS(L,R);
if(R==0)
{
printf("0\n");
continue;
}
if(n)
printf("%I64d\n",n);
else
{
printf("-1\n");
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
多校赛3- Solve this interesting problem 分类: 比赛 2015-07-29 21:01 8人阅读 评论(0) 收藏的更多相关文章
- H - Solve this interesting problem 分类: 比赛 2015-07-29 21:06 15人阅读 评论(0) 收藏
Have you learned something about segment tree? If not, don't worry, I will explain it for you. Segm ...
- 多校5-MZL's Border 分类: 比赛 2015-08-05 21:28 7人阅读 评论(0) 收藏
MZL's Border Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...
- short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- short-path problem (Dijkstra) 分类: ACM TYPE 2014-09-01 23:51 111人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏
D - Painter Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status P ...
- 山东理工大学第七届ACM校赛-LCM的个数 分类: 比赛 2015-06-26 10:37 18人阅读 评论(0) 收藏
LCM的个数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了 ...
- 山东理工大学第七届ACM校赛-完美素数 分类: 比赛 2015-06-26 10:36 15人阅读 评论(0) 收藏
完美素数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 我们定义:如果一个数为素数,且这个数中含有7或3,那么我们称这个数为完美 ...
- 山东理工大学第七届ACM校赛-经济节约 分类: 比赛 2015-06-26 10:34 19人阅读 评论(0) 收藏
经济节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 由于经济紧张,某国国王决定减少一部分多余的士兵,这些士兵在边界都有各自的 ...
随机推荐
- 不等高cell的搭建(一)
一.界面搭建 1.确定开发模式 如果界面是固定的,可以用xib 界面的一些内容不固定,就用纯代码 cell用什么方式去开发(我们采用纯代码和xib结合的方式) 2 ...
- 学习OpenCV——Kmean(C++)
从前也练习使用过OpenCV的Kmean算法,但是那版本低,而且也是基于C的开发.这两天由于造论文的需要把它重新翻出来在研究一下C++,发现有了些改进 kmeans C++: doublekmeans ...
- sdutoj 2154 Shopping
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2154 Shopping Time Limit: ...
- struts_20_对Action中所有方法、某一个方法进行输入校验(基于XML配置方式实现输入校验)
第01步:导包 第02步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app ...
- Android使用ZXing生成带图片的二维码
效果图如下: 制作过程很简单的就是在原始的二维码图片上添加一个logn图标,代码的注释写得很详细,也就不给大家啰嗦了 package com.example.day44_02_qrcodewithlo ...
- java文件下载 rest
/** * 返回文件二进制 * */ @GET @Path("/excel") @Produces("application/vnd.ms-excel; charset= ...
- Oracle数据库归档模式的切换及其相关操作详解
SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> ...
- 夺命雷公狗---node.js---11之文件上传
我们在做文件上传前需要用npm来安装一个插件先, 首先打开项目所在的目录,然后按住shift键然后右键鼠标进入命令行安装formidable 然后开始编写上传的静态页面: <!DOCTYPE h ...
- [Ubuntu] Ubuntu13.04, the desktop freezed after login
My os version is Ubuntu13.04, today, after started and logined, my desktop freezed. But i can still ...
- LR Socket 测试demo
建议像我这样最开始未接触过的,还是先从简单录制开始.录制完之后,分析测试脚本,再学习,再自己根据需要编写测试脚本. 第一:录制. A. B. 选择需要录制的exe的目录 ,填写完后点击ok. C ...