hdu5323 Solve this interesting problem(爆搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Solve this interesting problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1731 Accepted Submission(s): 519
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.
Each test case contains two integers L and R, as described above.
0≤L≤R≤109
LR−L+1≤2015
10 13
10 11
-1
12
比较隐晦的指出了爆搜的最大深度一定不会超过11层,所以,复杂度就是4^11次方,然后加一点可行性的剪枝之类,就能AC了
//#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
ll ans = ;
void dfs(ll l,ll r){
if(l<)return;
if(r<l)return;
if(l==){
if(ans==-)ans = r;
else ans = min(ans,r);
return;
}
if(r>=ans&&ans!=-)return;
if((r-l+)>(l))return;
dfs(l-(r-l)-,r);
dfs(l,r+(r-l));
dfs(l-(r-l)-,r);
dfs(l,r+(r-l)+);
return;
}
int main()
{
ios::sync_with_stdio(false);
ll l,r;
while(cin>>l>>r){
ans = -;
dfs(l,r);
cout<<ans<<endl;
}
return ;
}
hdu5323 Solve this interesting problem(爆搜)的更多相关文章
- HDU 5323 SOLVE THIS INTERESTING PROBLEM 爆搜
pid=5323" target="_blank" style="">链接 Solve this interesting problem Tim ...
- DFS+剪枝 HDOJ 5323 Solve this interesting problem
题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...
- 2015 Multi-University Training Contest 3 hdu 5323 Solve this interesting problem
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 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 ...
- 2019年牛客多校第二场 F题Partition problem 爆搜
题目链接 传送门 题意 总共有\(2n\)个人,任意两个人之间会有一个竞争值\(w_{ij}\),现在要你将其平分成两堆,使得\(\sum\limits_{i=1,i\in\mathbb{A}}^{n ...
- 多校赛3- Solve this interesting problem 分类: 比赛 2015-07-29 21:01 8人阅读 评论(0) 收藏
H - Solve this interesting problem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I ...
- HDU 4403 A very hard Aoshu problem(dfs爆搜)
http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- poj1077 Eight【爆搜+Hash(脸题-_-b)】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
随机推荐
- C# XmlSerializer序列化浅析
C# 中使用 XmlSerializer 实现类和xml文件的序列化和反序列化,使用起来非常简单. C# XmlSerializer实现序列化: XmlSerializer xml = new Xml ...
- C#模拟登录的htmlHelper类
public class HTMLHelper { /// <summary> /// 获取CooKie /// /// </summary> /// /// <para ...
- 转载:[Java]读取文件方法大全
转载网址:http://www.cnblogs.com/lovebread/archive/2009/11/23/1609122.html 1.按字节读取文件内容 2.按字符读取文件内容 3.按行读取 ...
- arm get_vector_swi_address
unsigned long* get_vector_swi_addr() { const void *swi_addr = 0xFFFF0008; unsigned ; unsigned ; unsi ...
- iOS中设置导航栏标题的字体颜色和大小
iOS中设置导航栏标题的字体颜色和大小,有需要的朋友可以参考下. 在平时开发项目的时候,难免会遇到修改导航栏字体大小和颜色的需求,一般使用自定义视图的方法,其实还存在一种方法. 方法一:(自定义视图的 ...
- Powershell ForEach-Object 循环
Powershell管道就像流水线,对于数据的处理是一个环节接着一个环节,如果你想在某一环节对流进来的数据逐个细致化的处理,可是使用ForEach-Object,$_ 代表当前的数据. 对管道对象逐个 ...
- java.lang.ClassNotFoundException错误原因汇总
开发java很长时间了,还经常会遇到java.lang.ClassNotFoundException这样的错误,最近又处理了一次,起初怀疑是jdk版本比class文件的编译版本低了导致了,但是运维人员 ...
- usaco5.5-Hidden Passwords
最小表示法,感觉可以做成个模板,第一次RE是因为字符串长度变2倍了而我把数组开小了 Executing... Test 1: TEST OK [0.008 secs, 3760 KB] Tes ...
- 潘石屹的SOHO小报猝死
东莞时报多媒体数字报刊平台 潘石屹的SOHO小报猝死
- eclipse java 配置
1.eclipse菜单 - Window - Preferences- Java - Installed JREs 2.eclipse菜单 - Window - Preferences- Java - ...