UVA 548(p155)----Tree
来源:互联网 发布:java中如何处理高并发 编辑:程序博客网 时间:2024/05/14 18:54
#include<bits/stdc++.h>using namespace std;const int INF=1e7;const int maxn=1e5;int n,ans,ansu;int lch[maxn],rch[maxn];int mid[maxn],last[maxn];int input(int*a){ string st; if(!getline(cin,st)) return 0; stringstream ss(st); int tmp; n=0; while(ss>>tmp) a[n++]=tmp; return n>0;}int build(int l1,int r1,int l2,int r2){ if(l1>r1) return 0; int root=last[r2]; int p=l1; while(mid[p]!=root) p++; int num=p-l1; lch[root]=build(l1,p-1,l2,l2+num-1); rch[root]=build(p+1,r1,l2+num,r2-1); return root;}void solve(int u,int sum){ sum+=u; if(!lch[u]&&!rch[u]) { if(sum<ans||(sum==ans&&ansu>u)) { ansu=u; ans=sum; } } if(lch[u]) solve(lch[u],sum); if(rch[u]) solve(rch[u],sum);}int main(){ ios::sync_with_stdio(0); while(input(mid)) { input(last); build(0,n-1,0,n-1); ansu=0; ans=INF; solve(last[n-1],0); cout<<ansu<<endl; } return 0;}题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=489
0 0
- UVA 548(p155)----Tree
- UVA 10870(p155)----Recurrences
- UVa 548 Tree
- uva 548 Tree
- uva 548 - Tree
- uva 548 - Tree
- UVa 548 - Tree
- uva 548 Tree
- uva 548 - Tree
- 数据结构 uva 548-Tree
- UVA 548 - Tree
- UVa 548 - Tree
- UVa 548 - Tree
- uva-548 Tree
- UVA 548 Tree
- UVA 548 tree
- uva 548 -Tree
- uva 548 Tree
- C# 5.0 使用任务调试表TaskScheduler来运行task
- UVA 540(p117)----Team Queue
- 在CentOS上MySQL数据库服务器配置方法
- BZOJ-2748 音量调节 DP+背包(脑残)
- APP引导页Demo
- UVA 548(p155)----Tree
- 嵌入式的一些面试问题
- JS下实现加号减号的数量加一减一
- MD5 delPhi 加密
- View Programming Guide for iOS 学习笔记_1
- ubuntu编译ffplay
- http和https的区别
- UVA 557(p344)----Burger
- HDU 1525 Eculid's Game(博弈)