随笔分类 -  stl库函数

摘要:sort学习笔记: 基本认识: sort并非只是普通的快速排序,除了对普通的快速排序进行优化,它还结合了插入排序和堆排序。根据不同的数量级别以及不同情况,能自动选用合适的排序方法。 头文件: 在C++中使用sort()函数需要使用#include<algorithm>头文件。algorithm意为" 阅读全文
posted @ 2023-11-17 14:51 我的秘密小屋 阅读(76) 评论(0) 推荐(0)
摘要:从四个vector里找四个数成一组,使得他们的和为零,问有几个这样的组。 class Solution { public: int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int> 阅读全文
posted @ 2023-03-22 10:59 我的秘密小屋 阅读(33) 评论(0) 推荐(0)
摘要:1、多用于判断一个元素在这个集合中是否出现过。 2、数组、set(去重)、map(自动排序)。 3、set是有序且 不允许有多个重复的键;unordered_set是无序的;multiset是允许有多个重复的键。 #include <set> int main(){ set<int>s; s.siz 阅读全文
posted @ 2023-03-21 14:57 我的秘密小屋 阅读(85) 评论(0) 推荐(0)
摘要:一、map的简介 1、map是STL的一个关联容器,map 容器中所有的元素都会根据元素对应的键值来排序,而键值key 是唯一值,并不会出现同样的键值key,也就是说假设已经有一个键值key 存在map 里,当同样的键值key 再insert 时,新的会覆盖掉旧的。 2、map内部所有的数据都是有序 阅读全文
posted @ 2023-03-21 12:31 我的秘密小屋 阅读(126) 评论(0) 推荐(0)
摘要:1 头文件 #include<vector> 2 定义 vector<int>vec; //定义一个int型向量 向量的意思就是一开始没有长度限制 vector<int>vec(10); //初始大小为10,这样就可以用数组的方式访问或者修改里面的值了。 vector<int>vec(10,1); 阅读全文
posted @ 2018-08-24 13:04 我的秘密小屋 阅读(151) 评论(0) 推荐(0)
摘要:string基操: #include<string> string a; cin>>a; 长度的获取: a.size(); 获得第一个字符: string:const_iterator it=s.begin(); count<<*it<<endl; 获得最后一个字符: string:const_it 阅读全文
posted @ 2018-08-24 11:17 我的秘密小屋 阅读(165) 评论(0) 推荐(0)
摘要:You are given two strings s and t, both consisting only of lowercase Latin letters.The substring s[l..r]is the string which is obtained by taking char 阅读全文
posted @ 2018-08-10 10:56 我的秘密小屋 阅读(477) 评论(0) 推荐(0)
摘要:Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant. The warehouse has m daily 阅读全文
posted @ 2018-08-09 14:58 我的秘密小屋 阅读(454) 评论(0) 推荐(0)
摘要:codeforces 910c 转自两位大佬:http://www.cnblogs.com/wkfvawl/p/9387634.html https://i.cnblogs.com/EditPosts.aspx?opt=1 You are given an array a consisting of 阅读全文
posted @ 2018-08-08 14:47 我的秘密小屋 阅读(182) 评论(0) 推荐(0)
摘要:codeforces 1003d n个硬币,q次询问。第二行给你n个硬币的面值(保证都是2的次幂!)。每次询问组成b块钱,最少需要多少个硬币? Example Input 5 42 4 8 2 4851410 Input Output 反向迭代器的rbegin和rend的位置 和正向迭代器的begi 阅读全文
posted @ 2018-08-08 10:43 我的秘密小屋 阅读(1564) 评论(0) 推荐(0)
摘要:1.使用string.h中的strrev函数 2.使用algorithm中的reverse函数 1.strrev函数只对字符数组有效,对string类型是无效的。 2.reverse函数是反转容器中的内容,对字符数组无效。 阅读全文
posted @ 2018-08-08 10:17 我的秘密小屋 阅读(345) 评论(0) 推荐(0)