【C++进阶】---- map和set的使用

1.序列式容器和关联式容器

前⾯我们已经接触过STL中的部分容器如:string、vector、list、deque、array、forward_list等,这些容器统称为序列式容器,因为逻辑结构为线性序列的数据结构,两个位置存储的值之间⼀般没有紧密的关联关系,⽐如交换⼀下,他依旧是序列式容器。顺序容器中的元素是按他们在容器中的存储位置来顺序保存和访问的。
关联式容器也是⽤来存储数据的,与序列式容器不同的是,关联式容器逻辑结构通常是⾮线性结构,两个位置有紧密的关联关系,交换⼀下,他的存储结构就被破坏了。顺序容器中的元素是按关键字来保存和访问的。关联式容器有map/set系列unordered_map/unordered_set系列。
本章节讲解的map和set底层是红⿊树,红⿊树是⼀颗平衡⼆叉搜索树。set是key搜索场景的结构,map是key/value搜索场景的结构。

2.set系列的使用

2.1set类的介绍

• set的声明如下,T就是set底层关键字的类型

• set默认要求T⽀持⼩于⽐较,如果不⽀持或者想按⾃⼰的需求⾛可以⾃⾏实现仿函数传给第⼆个模 版参数

• set底层存储数据的内存是从空间配置器申请的,如果需要可以⾃⼰实现内存池,传给第三个参 数。

• ⼀般情况下,我们都不需要传后两个模版参数。

• set底层是⽤红⿊树实现,增删查效率是,迭代器遍历是⾛的搜索树的中序,所以是有序 的。 O(logN)

• 前⾯部分我们已经学习了vector/list等容器的使⽤,STL容器接⼝设计,⾼度相似,所以这⾥我们 就不再⼀个接⼝⼀个接⼝的介绍,⽽是直接带着⼤家看⽂档,挑⽐较重要的接⼝进⾏介绍。

template < class T, // set::key_type/value_typeclass Compare = less<T>, // set::key_compare/value_compareclass Alloc = allocator<T> // set::allocator_type> class set;

2.2set的构造和迭代器

set的构造我们关注以下⼏个接⼝即可。 set⽀持正向和反向迭代遍历,遍历默认按升序顺序,因为底层是⼆叉搜索树,迭代器遍历⾛的中序;⽀持迭代器就意味着⽀持范围for,set的iterator和const_iterator都不⽀持迭代器修改数据,修改 关键字数据,破坏了底层搜索树的结构。

// empty (1) ⽆参默认构造 
explicit set (const key_compare& comp = key_compare(),const allocator_type& alloc = allocator_type());// range (2) 迭代器区间构造 
template <class InputIterator>set (InputIterator first, InputIterator last,const key_compare& comp = key_compare(),const allocator_type& = allocator_type());// copy (3) 拷⻉构造 
set (const set& x);// initializer list (5) initializer 列表构造 
set (initializer_list<value_type> il,const key_compare& comp = key_compare(),const allocator_type& alloc = allocator_type());// 迭代器是⼀个双向迭代器 
iterator -> a bidirectional iterator to const value_type// 正向迭代器 
iterator begin();
iterator end();// 反向迭代器 
reverse_iterator rbegin();
reverse_iterator rend();
#include<iostream>
#include<set>
#include<vector>
using namespace std;int main()
{// 1.无参构造set<int> s1;// 2.迭代器区间构造vector<int> v1 = { 1,2,2,3,4,5 };set<int> s2(v1.begin(), v1.end());// 3.拷贝构造set<int> s3(s2);// 4.链表构造set<int> s4({ 1,2,3,4,5,1,2 });return 0;
}

2.3set的增删改

set的增删查关注以下⼏个接⼝即可:

Member types
key_type -> The first template parameter (T)
value_type -> The first template parameter (T)// 单个数据插⼊,如果已经存在则插⼊失败 
pair<iterator,bool> insert (const value_type& val);// 列表插⼊,已经在容器中存在的值不会插⼊ 
void insert (initializer_list<value_type> il);// 迭代器区间插⼊,已经在容器中存在的值不会插⼊ 
template <class InputIterator>
void insert (InputIterator first, InputIterator last);// 查找val,返回val所在的迭代器,没有找到返回end() 
iterator find (const value_type& val);// 查找val,返回Val的个数 
size_type count (const value_type& val) const;// 删除⼀个迭代器位置的值 
iterator erase (const_iterator position);// 删除val,val不存在返回0,存在返回1 
size_type erase (const value_type& val);// 删除⼀段迭代器区间的值 
iterator erase (const_iterator first, const_iterator last);// 返回⼤于等val位置的迭代器 
iterator lower_bound (const value_type& val) const;// 返回⼤于val位置的迭代器 
iterator upper_bound (const value_type& val) const;

2.4insert和迭代器遍历使用案例

#include<iostream>
#include<set>
using namespace std;int main()
{// 去重+升序排序set<int> s1;// 去重+降序排序,给一个大于的仿函数//set<int,greater<int>> s1;s1.insert(1);s1.insert(1);s1.insert(2);s1.insert(3);//set<int>::iterator it1 = s1.begin();auto it1 = s1.begin();while (it1 != s1.end()){// error C3892: “it”: 不能给常量赋值 //*it1 = 1;cout << *it1 << " ";it1++;}cout << endl;// 插⼊⼀段initializer_list列表值,已经存在的值插⼊失败s1.insert({ 1,2,3,4 });for (auto e : s1){cout << e << " ";}cout << endl;set<string> strset = { "sort","insert","add" };// 遍历string比较ascll码大小顺序遍历的for (auto e : strset){cout << e << " ";}cout << endl;return 0;
}

2.5find和erase使用案例

#include<iostream>
#include<set>
using namespace std;int main()
{set<int> s1 = { 4,2,7,2,8,5,9 };for (auto e : s1){cout << e << " ";}cout << endl;// 删除最小值s1.erase(s1.begin());for (auto e : s1){cout << e << " ";}cout << endl;// 直接删除xint x;cin >> x;int num = s1.erase(x);if (num == 0){cout << x << "不存在!" << endl;}for (auto e : s1){cout << e << " ";}cout << endl;// 直接查找再利用迭代器删除xcin >> x;auto pos = s1.find(x);if (pos != s1.end()){s1.erase(pos);}else{cout << x << "不存在!" << endl;}for (auto e : s1){cout << e << " ";}cout << endl;// 算法库的查找O(N)auto pos1 = find(s1.begin(), s1.end(), x);// set自身实现的查找O(logN)auto pos2 = s1.find(x);// 利用count间接实现快速查找cin >> x;if (s1.count(x)){cout << x << "在!" << endl;}else{cout << x << "不在!" << endl;}return 0;
}

2.6multiset和set的差异

multiset和set的使⽤基本完全类似,主要区别点在于multiset⽀持值冗余,那么 insert/find/count/erase都围绕着⽀持值冗余有所差异,具体参看下⾯的样例代码理解。

find:

#include<iostream>
#include<set>
using namespace std;int main()
{// 相⽐set不同的是,multiset是排序,但是不去重 multiset<int> s = { 4,2,7,2,4,8,4,5,4,9 };for (auto e : s){cout << e << " ";}cout << endl;// 相⽐set不同的是,x可能会存在多个,find查找中序的第⼀个 int x;cin >> x;auto pos = s.find(x);while (pos != s.end() && *pos == x){cout << *pos << " ";pos++;}cout << endl;// 相⽐set不同的是,count会返回x的实际个数 cout << s.count(x) << endl;// 相⽐set不同的是,erase给值时会删除所有的xs.erase(x);for (auto e : s){cout << e << " ";}cout << endl;return 0;
}

3.map系列的使用

3.1map类型介绍

map的声明如下,Key就是map底层关键字的类型,T是map底层value的类型,set默认要求Key⽀持 ⼩于⽐较,如果不⽀持或者需要的话可以⾃⾏实现仿函数传给第⼆个模版参数,map底层存储数据的 内存是从空间配置器申请的。⼀般情况下,我们都不需要传后两个模版参数。map底层是⽤红⿊树实 现,增删查改效率是 O(logN) ,迭代器遍历是⾛的中序,所以是按key有序顺序遍历的。
template < class Key, // map::key_type key类型class T, // map::mapped_type value类型class Compare = less<Key>, // map::key_compare 数据比较class Alloc = allocator<pair<const Key,T> > //map::allocator_type 空间配置器> class map;

3.2pair类型介绍

map底层的红⿊树节点中的数据,使⽤pair<Key, T>存储键值对数据。
typedef pair<const Key, T> value_type;
template <class T1, class T2>
struct pair
{typedef T1 first_type;typedef T2 second_type;T1 first;T2 second;pair():first(T1()),second(T2()){}pair(const T1& a, const T2& b):first(a),second(b){}template<class U, class V>pair (const pair<U,V>& pr):first(pr.first),second(pr.second){}
};template <class T1,class T2>
inline pair<T1,T2> make_pair (T1 x, T2 y)
{return ( pair<T1,T2>(x,y) );
}

3.3map的构造

map的构造我们关注以下⼏个接⼝即可。
map的⽀持正向和反向迭代遍历,遍历默认按key的升序顺序,因为底层是⼆叉搜索树,迭代器遍历⾛ 的中序;⽀持迭代器就意味着⽀持范围for,map⽀持修改value数据,不⽀持修改key数据,修改关键 字数据,破坏了底层搜索树的结构。
// empty (1) ⽆参默认构造
explicit map (const key_compare& comp = key_compare(),const allocator_type& alloc = allocator_type());// range (2) 迭代器区间构造
template <class InputIterator>
map (InputIterator first, InputIterator last,const key_compare& comp = key_compare(),const allocator_type& = allocator_type());// copy (3) 拷⻉构造
map (const map& x);// initializer list (5) initializer 列表构造
map (initializer_list<value_type> il,const key_compare& comp = key_compare(),const allocator_type& alloc = allocator_type());// 迭代器是⼀个双向迭代器
iterator -> a bidirectional iterator to const value_type// 正向迭代器
iterator begin();
iterator end();// 反向迭代器
reverse_iterator rbegin();
reverse_iterator rend();
#include<iostream>
#include<map>
using namespace std;int main()
{// 无参默认构造map<int, int> m1;// 传参构造pair<string, int> p1 = { "英语",90 };pair<string, int> p2 = { "数学",95 };pair<string, int> p3 = { "语文",80 };map<string, int> m2 = { p1,p2,p3 };// 匿名对象初始化map<string, string> m3 = { pair<string, string>("insert", "插入") };// make_pair可自动推导模板参数类型,也可指定类型,make_pair<string,string>map<string, string> m4 = { make_pair("string","字符串") };// initializer_list构造map<string, string> m5 = { {"left", "左边"}, {"right", "右边"},
{"insert", "插⼊"},{ "string", "字符串" } };// 迭代器区间初始化map<string, string> m6(m5.begin(), m5.end());// 拷贝构造map<string, string> m7(m6);return 0;
}

3.4map的增删查

map的增删查关注以下⼏个接⼝即可:
map增接⼝,插⼊的pair键值对数据,跟set所有不同,但是查和删的接⼝只⽤关键字key跟set是完全 类似的,不过find返回iterator,不仅仅可以确认key在不在,还找到key映射的value,同时通过迭代 还可以修改value
Member types
key_type -> The first template parameter (Key)
mapped_type -> The second template parameter (T)
value_type -> pair<const key_type,mapped_type>// 单个数据插⼊,如果已经key存在则插⼊失败,key存在相等value不相等也会插⼊失败
pair<iterator,bool> insert (const value_type& val);// 列表插⼊,已经在容器中存在的值不会插⼊
void insert (initializer_list<value_type> il);// 迭代器区间插⼊,已经在容器中存在的值不会插⼊
template <class InputIterator>
void insert (InputIterator first, InputIterator last);// 查找k,返回k所在的迭代器,没有找到返回end()
iterator find (const key_type& k);// 查找k,返回k的个数
size_type count (const key_type& k) const;// 删除⼀个迭代器位置的值
iterator erase (const_iterator position);// 删除k,k存在返回0,存在返回1
size_type erase (const key_type& k);// 删除⼀段迭代器区间的值
iterator erase (const_iterator first, const_iterator last);

3.5map的数据修改

前⾯我提到map⽀持修改mapped_type 数据,不⽀持修改key数据,修改关键字数据,破坏了底层搜 索树的结构。
map第⼀个⽀持修改的⽅式时通过迭代器,迭代器遍历时或者find返回key所在的iterator修改,map 还有⼀个⾮常重要的修改接⼝operator[],但是operator[]不仅仅⽀持修改,还⽀持插⼊数据和查找数据,所以他是⼀个多功能复合接⼝。
需要注意从内部实现⻆度,map这⾥把我们传统说的value值,给的是T类型,typedef为
mapped_type。⽽value_type是红⿊树结点中存储的pair键值对值。⽇常使⽤我们还是习惯将这⾥的 T映射值叫做value。

operator[]内部调用insert,insert的返回值是pair<iterator,bool>,如果插入成功,返回的pair的first是新插入key所在节点的迭代器,second是true。如果插入失败,返回的pair的first是已经存在的key所在节点的迭代器,second是false。mapped_type()是value的默认构造,对于自定义成员会调用其默认构造,对于内置类型,如int,会初始化成0,double会初始化成0.0

插入成功的时候,operator[]具备了插入+修改的功能。

插入失败的时候,operator[]具备了查找+修改的功能。

Member types
key_type -> The first template parameter (Key)
mapped_type -> The second template parameter (T)
value_type -> pair<const key_type,mapped_type>// 查找k,返回k所在的迭代器,没有找到返回end(),如果找到了通过iterator可以修改key对应的
mapped_type值
iterator find (const key_type& k);// ⽂档中对insert返回值的说明
// The single element versions (1) return a pair, with its member pair::first
set to an iterator pointing to either the newly inserted element or to the
element with an equivalent key in the map. The pair::second element in the pair
is set to true if a new element was inserted or false if an equivalent key
already existed.// insert插⼊⼀个pair<key, T>对象
// 1、如果key已经在map中,插⼊失败,则返回⼀个pair<iterator,bool>对象,返回pair对象
first是key所在结点的迭代器,second是false
// 2、如果key不在在map中,插⼊成功,则返回⼀个pair<iterator,bool>对象,返回pair对象
first是新插⼊key所在结点的迭代器,second是true
// 也就是说⽆论插⼊成功还是失败,返回pair<iterator,bool>对象的first都会指向key所在的迭
代器
// 那么也就意味着insert插⼊失败时充当了查找的功能,正是因为这⼀点,insert可以⽤来实现
operator[]
// 需要注意的是这⾥有两个pair,不要混淆了,⼀个是map底层红⿊树节点中存的pair<key, T>,另
⼀个是insert返回值pair<iterator,bool>pair<iterator,bool> insert (const value_type& val);
mapped_type& operator[] (const key_type& k);// operator的内部实现
mapped_type& operator[] (const key_type& k)
{// 1、如果k不在map中,insert会插⼊k和mapped_type默认值,同时[]返回结点中存储mapped_type值的引⽤,那么我们可以通过引⽤修改返映射值。所以[]具备了插⼊+修改功能// 2、如果k在map中,insert会插⼊失败,但是insert返回pair对象的first是指向key结点的迭代器,返回值同时[]返回结点中存储mapped_type值的引⽤,所以[]具备了查找+修改的功能pair<iterator, bool> ret = insert({ k, mapped_type() });iterator it = ret.first;return it->second;
}

3.6构造遍历及增删查使用样例

#include<iostream>
#include<map>
using namespace std;int main()
{// initializer_list构造及迭代遍历map<string, string> dict = { {"left", "左边"}, {"right", "右边"},
{"insert", "插入"},{ "string", "字符串" } };auto it = dict.begin();while (it != dict.end()){//cout << (*it).first <<":"<<(*it).second << endl;// map的迭代基本都使⽤operator->,这⾥省略了⼀个->// 第一个->是迭代器运算符重载,返回pair*,第二个箭头是结构指针解引⽤取pair数据//cout << it.operator->()->first << ":" << it.operator->()-> second << endl;cout << it->first << ":" << it->second << endl;it++;}cout << endl;// insert插⼊pair对象的4种⽅式,对⽐之下,最后⼀种最⽅便pair<string, string> kv1("first", "第一个");dict.insert(kv1);dict.insert(pair<string, string>("second", "第二个"));dict.insert(make_pair("sort", "排序"));dict.insert({ "auto","自动的" });// map不允许键值冗余,已经存在的key会插入失败dict.insert({ "left", "左边,剩余" });for (const auto& e : dict){cout << e.first << ":" << e.second << endl;}cout << endl;// 查找string str;while (cin >> str){auto ret = dict.find(str);if (ret != dict.end()){cout << "->" << ret->second << endl;}else{cout << "查无此单词" << endl;}}// erase等接⼝跟set完全类似return 0;
}

3.7map的迭代器和[]功能样例

#include<iostream>
#include<map>
using namespace std;int main()
{// 1.利用find和iterator修改功能,统计水果出现次数string arr[] = { "苹果", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜",
"苹果", "香蕉", "苹果", "香蕉" };map<string, int> countMap;for (const auto& str : arr){// 先查找⽔果在不在map中// 1、不在,说明⽔果第⼀次出现,则插⼊{⽔果, 1}// 2、在,则查找到的节点中⽔果对应的次数++auto ret = countMap.find(str);if (ret == countMap.end()){countMap.insert({str,1});}else{ret->second++;}}for (const auto& e : countMap){cout << e.first << ":" << e.second << endl;}cout << endl;// 2.利⽤[]插⼊+修改功能,巧妙实现统计⽔果出现的次数map<string, int> countMap2;for (const auto& str : arr){// []先查找⽔果在不在map中// 1、不在,说明⽔果第⼀次出现,则插⼊{⽔果, 0},同时返回次数的引⽤,++⼀下就变成1次了// 2、在,则返回⽔果对应的次数++// 不在的时候[]具有查找+修改功能// 在的时候[]具有插入+修改功能countMap2[str]++;}for (const auto& e : countMap2){cout << e.first << ":" << e.second << endl;}// 3.[]的功能map<string, string> dict;dict.insert(make_pair("sort", "排序"));// key不存在->插⼊ {"insert", string()}dict["insert"];// 插⼊+修改dict["left"] = "左边";// 修改dict["left"] = "左边、剩余";// key存在->查找cout << dict["left"] << endl;return 0;
}

3.8multimap和map的差异

multimap和map的使⽤基本完全类似,主要区别点在于multimap⽀持关键值key冗余,那么
insert/find/count/erase都围绕着⽀持关键值key冗余有所差异,这⾥跟set和multiset完全⼀样,⽐如 find时,有多个key,返回中序第⼀个。其次就是multimap不⽀持[],因为⽀持key冗余,[]就只能⽀ 持插⼊了,不能⽀持修改。

4.两道相关题

4.1随机链表的复制

https://leetcode.cn/problems/copy-list-with-random-pointer/description/

// 1.随机链表的复制
/*
// Definition for a Node.
class Node {
public:int val;Node* next;Node* random;Node(int _val) {val = _val;next = NULL;random = NULL;}
};
*/// 1.
// 利用原链表的节点做key,新链表对应的节点做value
// 后续新链表的random就是nodeMap[cur->random]
// 通过原链表的random节点,找到新链表的random节点
class Solution {
public:Node* copyRandomList(Node* head) {map<Node*, Node*> nodeMap;Node* copyhead = nullptr, * copytail = nullptr;Node* cur = head;while (cur){if (copytail == nullptr){// 空链表copyhead = copytail = new Node(cur->val);}else{//尾插copytail->next = new Node(cur->val);copytail = copytail->next;}// 原链表节点做key,新链表节点做valuenodeMap[cur] = copytail;cur = cur->next;}cur = head;Node* copyCur = copyhead;while (cur){if (cur->random == nullptr){copyCur->random = nullptr;}else{copyCur->random = nodeMap[cur->random];}cur = cur->next;copyCur = copyCur->next;}return copyhead;}
};// 2.在原节点后面尾接新的相同的节点,然后copy->random=cur->random->next,然后在从原链表上分离
class Solution {
public:Node* copyRandomList(Node* head) {if (head == nullptr)return nullptr;Node* cur = head;while (cur){Node* newNode = new Node(cur->val);newNode->next = cur->next;cur->next = newNode;cur = cur->next->next;}cur = head;Node* copyCur = cur->next;while (cur){if (cur->random == nullptr){copyCur->random = nullptr;}else{copyCur->random = cur->random->next;}cur = cur->next->next;if (cur != nullptr)copyCur = copyCur->next->next;}Node* copyhead = nullptr, * copytail = nullptr;cur = head;while (cur){Node* nextNode = cur->next->next;if (copyhead == nullptr){copyhead = copytail = cur->next;}else{copytail->next = cur->next;copytail = copytail->next;}cur->next = nextNode;cur = nextNode;}return copyhead;}
};

4.2前k个高频单词

https://leetcode.cn/problems/top-k-frequent-words/submissions/661053571/

class Solution {
public:// 将words里的数据放入map中统计个数顺便排序// 再把map里的数据转入vectror中让sort排序,// 因为sort只支持随机迭代器容器的排序// 在写个仿函数指定比较规则struct kvCompare{bool operator()(const pair<string, int>& p1, const pair<string, int>& p2) const{return p1.second > p2.second ||(p1.second == p2.second && p1.first < p2.first);}};vector<string> topKFrequent(vector<string>& words, int k) {map<string, int> countMap;for (const auto& e : words){countMap[e]++;}vector<pair<string, int>> v(countMap.begin(), countMap.end());sort(v.begin(), v.end(), kvCompare());//stable_sort(v.begin(), v.end(), kvCompare());// stable_sort是稳定排序,不会破坏顺序,只写return p1.second > p2.second即可vector<string> ret;for (int i = 0; i < k; i++){ret.push_back(v[i].first);}return ret;}
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/98571.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/98571.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

430章:Python Web爬虫入门:使用Requests和BeautifulSoup

在软件交付日益高频、用户需求快速迭代的今天&#xff0c;版本发布流程的规范性直接决定了团队的交付效率、产品质量和用户满意度。然而&#xff0c;许多团队仍面临以下痛点&#xff1a;发布混乱&#xff1a;分支管理随意&#xff0c;代码冲突频发&#xff1b;质量失控&#xf…

代码随想录第七天|● 454.四数相加II ● 383. 赎金信 ● 15. 三数之和 18.四数之和

本文所有题目链接/文章讲解/视频讲解&#xff1a;https://programmercarl.com/0454.%E5%9B%9B%E6%95%B0%E7%9B%B8%E5%8A%A0II.html 454.四数相加II 有四个数组&#xff0c;如果要遍历则时间复杂度太大 可以选择分组&#xff0c;a和b一组&#xff0c;c和d一组 这样就可以等同于…

Vue3源码reactivity响应式篇之computed计算属性

概述 vue3中&#xff0c;computed函数用于表示计算属性&#xff0c;有惰性求值、响应式追踪依赖的特点。本文将介绍computed的实现原理以及其机制细节。 源码解析 computed计算属性和computed方法、ComputedRefImpl类以及refreshComputed方法有关。 computed方法 computed暴露给…

[嵌入式embed]Keil5烧录后STM32不自动运行,复位才能运行

[嵌入式embed]Keil5烧录后STM32不自动运行,复位才能运行Keil5-验证“Reset and Run”功能是否生效参考文章Keil5-验证“Reset and Run”功能是否生效 参考文章 Keil5烧录后STM32不自动运行&#xff1f;必须复位才能启动的终极解决方案

阿里云Qwen3系列模型部署微调评测

与阿里云一起轻松实现数智化让算力成为公共服务&#xff1a;用大规模的通用计算&#xff0c;帮助客户做从前不能做的事情&#xff0c;做从前做不到的规模。让数据成为生产资料&#xff1a;用数据的实时在线&#xff0c;帮助客户以数据为中心改变生产生活方式创造新的价值。模型…

北京鲁成伟业 | 三屏加固笔记本电脑C156F3

在工业控制、应急指挥、测控及无人机作业等对设备稳定性与环境适应性要求较高的领域&#xff0c;一款性能均衡且坚固耐用的计算机往往能为工作效率提供有力支撑。三屏加固笔记本电脑C156F3便是针对这类需求设计的设备&#xff0c;凭借多方面的特性&#xff0c;可满足不同场景下…

七彩氛围灯芯片EH3A01RGB驱动芯片定时开关IC方案

‍在现代智能家居和个性化照明领域&#xff0c;EH3A01-442A-A24F小夜灯定时芯片凭借其多功能、低功耗和灵活配置的特点&#xff0c;成为LED氛围灯、小夜灯及便携式照明方案的理想选择。本文将深入解析该芯片的核心功能、电气特性及应用场景&#xff0c;帮助开发者与用户全面掌握…

Spring Boot 项目新增 Module 完整指南

1. 模块化开发的重要性 在软件开发中&#xff0c;随着项目规模的不断扩大&#xff0c;​​模块化设计​​已成为提高代码可维护性和可复用性的关键实践。通过将大型项目拆分为多个独立模块&#xff0c;开发团队可以​​并行开发​​不同功能组件&#xff0c;降低代码耦合度&…

Git cherry-pick 与分支重置技术实现代码健全性保障下的提交记录精简

代码健全性保障&#xff1a;上市审查中的 Git 提交记录整理方案&#xff08;核心功能提交筛选流程&#xff09; 一、背景与目的 我司正处于上市筹备阶段&#xff0c;券商需对核心系统进行 Git 代码审查&#xff0c;并基于提交记录生成测试报告。由于原始提交记录包含大量细节性…

前后端联调时出现的一些问题记录

服务器的ip没有设置成所有ip都能访问的&#xff0c;或防火墙没开跨域问题&#xff08;刚开始异源&#xff0c;有这个问题&#xff0c;主要是前端做一下配置代理&#xff0c;后端也可以配置跨域资源共享&#xff08;CORS&#xff09;&#xff09;Configuration public class Cor…

数字图像处理-设计生成一个半球

1 实验题目设计生成一个半球&#xff08;matlab&#xff09;。2 程序源代码%Hemisphere clear,clc,close all %Sphere radius R1; %Set grid number n30; theta (-n:2:n)/n*pi; phi ([0,0:2:n])/n*pi/2; cosphi cos(phi); cosphi(1) 0; cosphi(end) 0; sintheta sin(thet…

mac M1上安装windows虚拟机报错

Parallels版本是18.0.02 mac&#xff1a;arm系统15.6.1 自动获取windows11下载&#xff0c;安装的时候报错&#xff0c;蓝屏&#xff0c;是因为安装的版本不对&#xff0c;猜测原因应该是18.0.02不支持最新版的windows11&#xff0c;需要更新最新版的Parallels。 解决方案&am…

基于R语言机器学习方法在生态经济学领域中的实践技术应用

近年来&#xff0c;人工智能领域已经取得突破性进展&#xff0c;对经济社会各个领域都产生了重大影响&#xff0c;结合了统计学、数据科学和计算机科学的机器学习是人工智能的主流方向之一&#xff0c;目前也在飞快的融入计量经济学研究。表面上机器学习通常使用大数据&#xf…

第01章 初识MySQL与mysql8.0的安装

初识 MySQL 文章目录初识 MySQL引言一、数据库基础1.1 什么是数据库1.2 表1.3 数据类型1.4 主键二、数据库技术构成2.1 数据库系统2.2 SQL 语言2.2.1 数据定义语言&#xff08;DDL&#xff09;2.2.2 数据操作语言&#xff08;DML&#xff09;2.2.3 数据查询语言&#xff08;DQL…

【数据结构基础习题】-1- 数据结构基本操作

一、顺序表和链表习题 1. 顺序表就地逆置#include <stdio.h> // 定义顺序表结构 #define MAXSIZE 100 typedef struct {int data[MAXSIZE];int length; } SqList; // 就地逆置顺序表 void reverseList(SqList *L) {int i, temp;for (i 0; i < L->length / 2; i) {…

【Java实战㉞】从0到1:Spring Boot Web开发与接口设计实战

目录一、Spring Boot Web 基础配置1.1 Web 起步依赖&#xff08;spring-boot-starter-web 导入与核心组件&#xff09;1.2 内置服务器配置&#xff08;Tomcat 端口、线程池、连接超时设置&#xff09;1.3 静态资源访问&#xff08;静态资源存放路径、自定义资源映射&#xff09…

房屋安全鉴定机构评价

房屋安全鉴定机构评价&#xff1a;如何选择专业可靠的检测服务在建筑行业快速发展的今天&#xff0c;房屋安全鉴定已成为保障建筑安全、预防事故的重要环节。面对市场上众多的房屋安全鉴定机构&#xff0c;如何科学评价并选择一家专业可靠的服务提供方&#xff0c;是许多业主、…

【算法专题训练】19、哈希表

1、哈希表基础知识 以键值对的方式进行数据存储优点&#xff1a;哈希表数据结构在插入、删除或查找一个元素时&#xff0c;都只需要O(1)的时间 哈希表设计三要点&#xff1a; 为了快速确定一个元素在哈希表中的位置&#xff0c;可以使用一个数组&#xff0c;元素的位置为他的…

某光伏电力监控系统网络安全监测项目:智能组网技术优化方案实践

背景与挑战随着光伏电力行业的快速发展&#xff0c;光伏电站的规模和分布范围日益扩大。电力监控系统作为光伏电站的核心平台&#xff0c;其网络安全直接关系到电力生产的稳定性与可靠性。然而&#xff0c;光伏场站通常分布在偏远地区&#xff0c;网络环境复杂&#xff0c;传统…

GEE训练教程:基于Landsat 8卫星影像识别并提取指定区域内无云覆盖的区域多边形,最终导出为矢量文件

简介 本文使用Google Earth Engine平台,通过Landsat 8卫星影像识别并提取指定区域内无云覆盖的区域多边形,最终导出为矢量文件。主要步骤包括:定义研究区域、创建云检测算法、筛选高质量影像、将无云区域转换为矢量多边形,并进行可视化检查和数据导出。 使用Google Earth…