Solve this interesting problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1020    Accepted Submission(s): 279

Problem Description
Have you learned something about segment tree? If not, don’t worry, I will explain it for you.
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: Lu and Ru.
- If Lu=Ru, u is a leaf node. 
- If Lu≠Ru, u has two children x and y,with Lx=Lu,Rx=⌊Lu+Ru2⌋,Ly=⌊Lu+Ru2⌋+1,Ry=Ru.
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 Lroot=0 and Rroot=ncontains a node u with Lu=L and Ru=R.

Input
The input consists of several test cases. 
Each test case contains two integers L and R, as described above.
0≤L≤R≤109
LR−L+1≤2015
Output
For each test, output one line contains one integer. If there is no such n, just output -1.
Sample Input
6 7 10 13 10 11
Sample Output
7 -1 12
Source
2015 Multi-University Training Contest 3
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5325 5324 5323 5322 5321 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <assert.h>
 4 #include <algorithm>
 5 const long long inf=(long long) 1e30;
 6
 7 long long n;
 8
 9 /*int look(int x)
10 {
11     if(x%2==0)
12         return 2;
13     else
14         return 1;
15 }*/
16
17 void dfs(long long l,long long r)
18 {
19     if(l<0 || r>inf)
20         return;
21     if(l==0)
22     {
23         if(r<n)
24             n=r;
25         return ;
26     }
27     if(l<r-l+1)
28         return;
29     if(r-l+1!=1)
30         dfs(l,r+(r-l+1)-1);
31     dfs(l-(r-l+1),r);
32     dfs(l-(r-l+1)-1,r);
33     dfs(l,r+(r-l+1));
34     return;
35 }
36
37 int main()
38 {
39     int L,R;
40     while(scanf("%d %d",&L,&R)!=EOF)
41     {
42         assert(0 <= L && L <= (int)1e9);
43         assert(0 <= R && R <= (int)1e9);
44         assert(L <= R);
45         assert(L / (R - L + 1) <= 2015);
46         n=inf;
47         dfs((long long) L,(long long) R);
48         if(n==inf)
49             printf("-1\n");
50         else
51             printf("%I64d\n",n);
52     }
53     return 0;
54 }

View Code

转载于:https://www.cnblogs.com/cyd308/p/4685222.html

多校3 1008 Solve this interesting problem相关推荐

  1. HDU 1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...

  2. hdu 1086 A - You can Solve a Geometry Problem too (线段的规范相交非规范相交)

    A - You can Solve a Geometry Problem too Time Limit:1000MS     Memory Limit:32768KB     64bit IO For ...

  3. HDU1086You can Solve a Geometry Problem too(判断线段相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  4. 【后缀数组】【线段树】codeforces102028H Can You Solve the Harder Problem?

    H. Can You Solve the Harder Problem? time limit per test6.0 s memory limit per test1024 MB inputstan ...

  5. HDU 1086 You can Solve a Geometry Problem too (判断线段交叉,线段跨立)

    You can Solve a Geometry Problem too   Time Limit:1000MS     Memory Limit:32768KB     64bit IO Forma ...

  6. You can Solve a Geometry Problem too(线段相交问题)

     Problem Description Many geometry(几何)problems were designed in the ACM/ICPC. And now, I also prep ...

  7. hdu-You can Solve a Geometry Problem too

    http://acm.hdu.edu.cn/showproblem.php?pid=1086 题意:判断两两直线相交的个数 code: #include<cstdio> #include& ...

  8. 大教堂和集市--两种不同的软件开发模式 论文阅读笔记

    该博文来自<The Cathedral and the Bazaar>一文的阅读总结,再加入一些自己的理解. 今天又发现网上的一个资料,可以说是对本文的一个纲领吧:大教堂与集市--维基语录 ...

  9. Codeforces Round #411 (Div. 2) A-F

    比赛时候切了A-E,fst了A Standings第一页只有三个人挂了A题,而我就是其中之一,真™开心啊蛤蛤蛤 A. Fake NP time limit per test 1 second memo ...

最新文章

  1. 应届生想要获取web前端开发岗位?这份技能攻略,面试攻略别错过!
  2. linux系统自签发免费ssl证书,为nginx生成自签名ssl证书
  3. 旋转根组件 Learn Unreal Engine (with C++)
  4. 10个常见的缓存使用误区
  5. 阿里云服务器内核编译升级
  6. typedef和define的用法和区别
  7. aⅴgo安装包下载_Mysql 安装
  8. Dart入门—库、泛型与异常
  9. Java 开发新选择?Apache NetBeans IDE 9.0 正式发布
  10. PAT 1018 锤子剪刀布
  11. 在java中调用python方法
  12. 如何在Visio中插入公式符号
  13. 嵌入式开发的基础知识大揭秘
  14. 网站地图制作百度地图google地图制作方法
  15. RabbitMQ服务启动成功后就自动停止
  16. 齐岳提供的双核金属铱配合物黏度探针C10((df-ppy)2Ir(bpy)(CH2)10(bpy)Ir(btph)22+)-
  17. 群晖经典第三方套件_使用群晖第三方套件进行IPV6的DDNS
  18. 逆序对 矩阵 好事成双 金牌银牌铜牌 发工资
  19. 极兔一面:10亿级ES海量搜索狂飙10倍,该怎么办?
  20. JAVA分页代码实例

热门文章

  1. 21天Jmeter打卡Day20 响应断言,JSON断言
  2. 人生难免有失意,还是个小姑娘的她...成功的转行测试岗拿到18k offer
  3. 怎样开图纸便宜_干货技能 | 十大技巧,吃透建筑施工图纸!
  4. java安装时无法写入文件_Java - 无法写入第二个文件
  5. CO1 Introduction
  6. AI学习笔记(三)特征选择与提取、边缘提取
  7. c语言产生带字母的随机数,菜鸟求助,写一个随机输出26个英文字母的程序
  8. pooleddb mysql_使用dbutils的PooledDB连接池,操作数据库
  9. 正在搜索开发人员模式安装包_每个 Java 开发人员都应该知道的 10 个基本工具...
  10. 2020推荐系统算法一览、实践