【搜索】 HDU 5323 Solve this interesting problem
来源:互联网 发布:淘宝里的旺旺号是什么 编辑:程序博客网 时间:2024/04/30 14:17
点击打开链接
用线段树方式建树 [ 0, n]
已知[ l, r] 结点 求n
若 建一个[0, 2*r] 的线段树 这是的总点数的奇的,(左子树!=右子树
[0, r] 在左子树里 则n最大为2*r
若 建一个[0, 2*r+1] 的线段树 (左子树==右子树
[0, r] 在左子树里 这时则 [0, r] 就可以建树
所以搜的时候超出2*r 就直接return
#include <cstdio>#include <cstring>#include <cstdlib>#include <string>#include <iostream>#include <algorithm>#include <sstream>#include <cmath>using namespace std;#include <queue>#include <stack>#include <vector>#include <deque>#define cler(arr, val) memset(arr, val, sizeof(arr))#define FOR(i,a,b) for(int i=a;i<=b;i++)#define IN freopen ("in.txt" , "r" , stdin);#define OUT freopen ("out.txt" , "w" , stdout);typedef long long LL;const int MAXN = 101000;const int MAXM = 200000;const int INF = 0x3f3f3f3f;const int mod = 1000000007;const double eps= 1e-8;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1LL ans,flag,L,R;void dfs(LL l,LL r){ if(r>2*R||flag&&r>=ans) return ; if(l==0) { flag=1; ans=r; return ; } LL len=r-l+1; if(l-len-1>=0) dfs(l-len-1,r); if(l-len>=0) dfs(l-len,r); dfs(l,r+len-1); dfs(l,r+len);}int main(){ while(scanf("%I64d%I64d",&L,&R)!=EOF) { ans=INF;flag=0; dfs(L,R); if(ans==INF) puts("-1"); else printf("%I64d\n",ans); } return 0;}/**/
0 0
- 【搜索】 HDU 5323 Solve this interesting problem
- hdu 5323 Solve this interesting problem dfs搜索
- hdu 5323 Solve this interesting problem dfs 搜索
- Hdu 5323 Solve this interesting problem(搜索)
- HDU 5323 Solve this interesting problem
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
- HDU 5323 Solve this interesting problem(暴搜)
- hdu 5323 Solve this interesting problem 【DFS】
- hdu 5323 Solve this interesting problem
- HDU 5323 Solve this interesting problem(DFS)
- HDU 5323Solve this interesting problem(DFS)
- Hdu 5323 Solve this interesting problem【Dfs】
- HDOJ 5323 Solve this interesting problem BFS搜索
- hdu 5323 Solve this interesting problem(dfs)
- HDU 5323 Solve this interesting problem(DFS)
- Solve this interesting problem
- H - Solve this interesting problem
- HDU5323.Solve this interesting problem
- 常用SQL
- window基本知识
- android适配浅析
- 防火墙问题
- 通过“分布式系统的8大谬误”反思APP的设计 第六篇 谬误6:只有一个管理者
- 【搜索】 HDU 5323 Solve this interesting problem
- java学习笔记(六) collections--stack
- html基础2
- 55. Jump Game
- Volley学习笔记(二):使用Volley加载网络图片
- 七月日记
- Android核心基础-7.Android 网络通信-1.获取文本数据
- 在windows系统下修改hosts文件,使其可以修改
- poj 3660 Floyd应用(确定牛的位置)