set的基本使用
来源:互联网 发布:人才系统java源码 编辑:程序博客网 时间:2024/04/29 10:55
set的英文意思是“集合”, 集合都不陌生吧,集合的特点有唯一性,即:每一个元素只有一个,所以set可以用来“去重”操作,set还有默认的排序。
1、头文件——<set>
2、定义——set<int>Q;
3、输入(插入)——insert(x);
4、有序输出
set<int>::iterator it;
for(it = Q.begin(); it != Q.end(); it++)
cout<<*it<<endl;
5、删除制定元素——erase(x);
6、清空——clare();
7、判空——empty();
8、大小——size();
9、二分查找——Q.lower_bound(x);
L2-014. 列车调度
Pat上的一个题目,用set完美的解决了。
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <stack>#include <math.h>#include <vector>#include <set>using namespace std;typedef long long LL;const int inf = 0X3f3f3f3f;const int Max = 10000;int main(int argc, char** argv) { int i, j, k; int n, x; set<int>s; cin>>n; for(i = 0; i < n; i++) { cin>>x; if(s.empty()) { s.insert(x); } else { set<int>::iterator it; it = s.lower_bound(x); if(it == s.end()) { s.insert(x); } else { s.erase(it); s.insert(x); } } } int t = s.size(); cout<<t<<endl; return 0;}
0 0
- set的基本使用
- STL之set的基本使用
- set的基本操作
- set的基本用法
- set的基本使用方法
- uvaoj 10815 Andy's First Dictionary set的基本使用
- java中set和get的基本使用
- STL之Set:Set的基本用法
- STL之Set:Set的基本用法
- STL之Set:Set的基本用法
- STL set的基本操作
- [数据结构] Set的基本用法
- Set集合的基本操作
- STL的set基本用法
- STL之set、map基本使用实例
- Visual C++下使用ADO的Connection对象及其Record set对象的基本步骤
- stl set的使用
- set的使用
- 1.7生成模型和判别模型
- 测试圆珠笔 测试用例 为什么选择做测试
- 欢迎使用CSDN-markdown编辑器
- github 新建组织 新建仓库 [U02]
- String类(一)
- set的基本使用
- 算法之栈的实现2
- [gSOAP]MFC调用WEBService 中文乱码
- 新手在路上! Android UI界面设计
- 选择排序算法实现
- Linux curl命令详解
- mysql如何查询最新的20条记录
- C++11之std--future和std--promise
- 深入探索透视纹理映射(下)