前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >set使用实例1+lower_bound(val)(个人模版)

set使用实例1+lower_bound(val)(个人模版)

作者头像
Angel_Kitty
发布2018-04-08 15:22:26
5980
发布2018-04-08 15:22:26
举报

set使用实例1+lower_bound(val):

代码语言:javascript
复制
 1 #include<stdio.h>  
 2 #include<set>  
 3 #include<iostream>  
 4 #include<algorithm>  
 5 #include<string.h>  
 6 #include<map>  
 7 using namespace std;  
 8 int main()  
 9 {  
10     int n;  
11     while(~scanf("%d",&n))  
12     {  
13         map<int ,int>lson,rson;  
14         set<int >s;  
15         set<int >::iterator pos;  
16         for(int i=0;i<n;i++)  
17         {  
18             int x;  
19             scanf("%d",&x);  
20             if(i==0)  
21             {  
22                 s.insert(x);  
23                 continue;  
24             }  
25             pos=s.lower_bound(x);  
26             if(pos!=s.end()&&lson[*pos]==0)  
27             {  
28                 lson[*pos]=x;  
29             }  
30             else  
31             {  
32                 pos--;  
33                 rson[*pos]=x;  
34             }  
35             printf("%d ",*pos);  
36             s.insert(x);  
37         }  
38         printf("\n");  
39     }  
40 }  
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-03-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档