codeforces 675D Tree Construction (map)
来源:互联网 发布:c语言读取bin文件内容 编辑:程序博客网 时间:2024/06/03 13:46
题目链接:http://codeforces.com/contest/675/problem/D
题意:建立一棵二叉搜索树,比当前节点小的放左边,否则放右边。问编号2~n的节点的父节点数值是多少。
思路:如果用普通的建树方法来做,在遇到深度较深的树时会超时。map的lower_bound(t)返回第一个key大于等于t的位置it,所以t必定在(it.second,it.first)之间。
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+5;map <int ,int> q;int a[N];int main(){ int n; scanf("%d %d",&n ,&a[1]); q[a[1]] = q[1e9] = a[1]; for(int i=2;i<=n;i++) { scanf("%d",&a[i]); map<int,int>::iterator it = q.lower_bound(a[i]); printf("%d " ,(*it).second);q[a[i]] = (*it).second = a[i]; } return 0;}
0 0
- codeforces 675D Tree Construction (map)
- codeforces 675D Tree Construction(set)
- codeforces 675D Tree Construction(set)
- codeforces-675D Tree Construction
- CodeForces - 675D Tree Construction (set&数据结构)
- Codeforces 675D Tree Construction (splay)
- Codeforces 675D Tree Construction【构造,BST】
- Codeforces 675D Tree Construction【思维+set】
- 【CF 675D】 Tree Construction(离线二分+左右指针)
- Codeforces 675C Money Transfers 【思维】 + 675D Tree Construction 【二分】
- Codeforces Round #353 (Div. 2) D. Tree Construction (二叉搜索树+set)
- Codeforces Round #353 (Div. 2) D. Tree Construction (构造二叉搜索树)
- Codeforces Round #353 (Div. 2) D. Tree Construction
- Codeforces Round #353 (Div. 2)D. Tree Construction
- Codeforces Round #353 (Div. 2) D. Tree Construction (BST)
- Codeforces Round #353 (Div. 2) D. Tree Construction
- codeforces round353 tree construction
- Codeforces Round #353 (Div. 2) D. Tree Construction __ Binary Search Tree
- bzoj 3754 Tree之最小方差树
- ARM寄存器介绍
- Python每天一题 0000
- PAT B1016: 部分A+B
- Terracotta Java分布式任务调度平台 - Quartz
- codeforces 675D Tree Construction (map)
- Linux 历史上 25 个里程碑事件回顾
- Mongodb连接java
- 如何实现可配置的后台
- PAT(B) - 1054. 求平均值 (20)
- 移植u-boot学习笔记3-----分析启动过程之重定位
- mysql修改事务隔离级别
- java进阶知识点总结
- 给 Android 开发者的 RxJava 详解