2015 Multi-University Training Contest 3 1008
2015-07-29 20:26
411 查看
Solve this interesting problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1728 Accepted Submission(s): 517
[align=left]Problem Description[/align]
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.
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 using namespace std; const int INF=0x3f3f3f3f; LL L,R,ans; void DFS(LL l,LL r) { LL len=r-l+1; //区间长度 if(r>=ans) return ; if(l==0) { ans=r; return ; } //结束递归 if(len>l) return ; DFS(2*l-r-1,r); DFS(2*l-r-2,r); DFS(l,2*r-l); DFS(l,2*r-l+1); } int main() { //freopen("in.txt","r",stdin); while(scanf("%I64d %I64d",&L,&R)!=EOF) { ans=INF; DFS(L,R); if(ans==INF) cout<<"-1"<<endl; else cout<<ans<<endl; } return 0; }
View Code
相关文章推荐
- 2015 Multi-University Training Contest 3 1002 RGCDQ
- ZOJ 3450 Doraemon's Railgun
- debug : StartService failed, getlasterror = 0x7f(127) 转
- Failure [INSTALL_FAILED_OLDER_SDK] [每件问题100块]
- 多校赛3- Painter
- 多校赛3- Painter 分类: 比赛 2015-07-29 19:58 3人阅读 评论(0) 收藏
- dlopen failed: "*.so" has unexpected e_machine
- EAGAIN、EWOULDBLOCK、EINTR与非阻塞 长连接
- hdu-5316 Magician (2015 Multi-University Training Contest 3)
- HUAS Summer Trainning #3~A
- UVa 10651 Pebble Solitaire(状态压缩DP)
- HTTP1.1中CHUNKED编码解析 http://blog.csdn.net/zhangboyj/article/details/6236780
- 2015多校第一场1006 hdu 5293 Tree chain problem
- Core Animaiton - 7
- Mybaits中Association元素使用
- uva 10976 Fractions Again(简单枚举)
- Rails 应用使用 Capistrano2 部署流程
- Rails 应用使用 Capistrano2 部署流程
- 使用dubbo2.5出现A child container failed during start
- 2015 Multi-University Training Contest 3 || HDU 5325 Crazy Bobo || 类似bfs