STL 核心模塊

很好!你想深入 STL(Standard Template Library)和容器算法,是學習 C++ 非常關鍵的一步。下面我給你整理一份STL 容器 + 算法的入門指南,適合從零起步掌握這部分內容。


🌟 一、STL 核心模塊

STL 分為三大塊,你主要先掌握前兩塊:

  1. 容器(Containers) 👉 存放數據的結構
  2. 算法(Algorithms) 👉 操作容器里的數據
  3. 迭代器(Iterators)👉 算法和容器的橋梁

📦 二、常用容器分類 + 用法示例

類型容器特點
順序容器vector, list, deque有序訪問,插入刪除位置有限制
關聯容器set, map自動排序,基于紅黑樹
無序容器unordered_set, unordered_map基于哈希表,查找快但無序
適配器stack, queue, priority_queue封裝其他容器提供特定操作

例子:使用 vector

#include <vector>
#include <iostream>
using namespace std;int main() {vector<int> v = {1, 2, 3};v.push_back(4);       // 添加元素v.pop_back();         // 刪除末尾cout << v[0] << endl; // 訪問元素
}

🧠 三、常用算法(頭文件 <algorithm>

STL 提供了 80 多種常用算法,先學這些最基礎的:

分類代表函數用法示例
排序sort(v.begin(), v.end())排序 vector
查找find, count, binary_search判斷是否存在某個元素
遍歷for_each, transform應用函數到每個元素
修改reverse, replace, fill反轉、替換、填充

例子:排序 + 查找

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;int main() {vector<int> v = {3, 1, 4, 2};sort(v.begin(), v.end());      // 排序if (binary_search(v.begin(), v.end(), 3))cout << "Found 3" << endl;
}

🔄 四、迭代器的用法(配合容器+算法)

所有容器都有 .begin().end() 返回迭代器。

vector<int> v = {1, 2, 3};
for (auto it = v.begin(); it != v.end(); ++it)cout << *it << " ";

🛠 五、推薦學習順序

  1. 掌握 vector, set, map 的基本用法
  2. 學會使用 sort, find, count, reverse 等常見算法
  3. 理解迭代器是怎么配合算法工作的
  4. 學會寫 lambda 來配合 sortfor_each
  5. 開始寫簡單的項目/功能:統計詞頻、模擬排行榜、實現任務隊列

好!下面是針對每類容器精心設計的小練習題 + 示例代碼,每題只用一種容器,幫助你理解用法和適用場景:

🧱 1. 順序容器練習題:vector

📌 題目:輸入一組整數,輸出其中所有大于5的數,按升序排列

? 示例代碼:

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;int main() {vector<int> nums = {3, 7, 1, 9, 5, 6};vector<int> result;for (int x : nums)if (x > 5) result.push_back(x);sort(result.begin(), result.end());  // 升序排序for (int x : result)cout << x << " ";  // 輸出:6 7 9
}

🌲 2. 關聯容器練習題:set

📌 題目:輸入一組數字,輸出去重后的升序結果

? 示例代碼:

#include <iostream>
#include <set>
using namespace std;int main() {set<int> s;int a[] = {5, 1, 2, 2, 3, 5, 4};for (int x : a)s.insert(x);  // 自動排序+去重for (int x : s)cout << x << " ";  // 輸出:1 2 3 4 5
}

? 3. 無序容器練習題:unordered_map

📌 題目:統計字符串中每個字符的出現次數(頻次統計)

? 示例代碼:

#include <iostream>
#include <unordered_map>
using namespace std;int main() {string s = "abracadabra";unordered_map<char, int> freq;for (char c : s)freq[c]++;for (auto& p : freq)cout << p.first << ": " << p.second << endl;// 示例輸出(順序不固定):// a: 5// b: 2// r: 2// c: 1// d: 1
}

🎒 4. 容器適配器練習題:stack

📌 題目:檢查一個括號字符串是否左右匹配

例如 "(()())" 匹配,"(()" 不匹配。

? 示例代碼:

#include <iostream>
#include <stack>
using namespace std;bool isValid(string s) {stack<char> stk;for (char c : s) {if (c == '(') stk.push(c);else if (c == ')') {if (stk.empty()) return false;stk.pop();}}return stk.empty();
}int main() {string test = "(()())";cout << (isValid(test) ? "匹配" : "不匹配") << endl;
}

? 總結練習與容器匹配

容器小題練習關鍵詞
vector篩選+排序線性數據
set去重+排序唯一集合
unordered_map統計頻率快速查找
stack括號匹配后進先出

下面按 四大類 + 每類具體容器 給出簡單易懂的例子和對應代碼,幫助你快速掌握它們的用法。


1. 順序容器(Sequence Containers)

1.1 vector

場景:存一組學生分數,按索引隨機訪問

#include <iostream>
#include <vector>
using namespace std;int main() {vector<int> scores = {85, 90, 78};scores.push_back(92);         // 在末尾添加一個分數cout << "第三個學生的分數是:" << scores[2] << endl;  // 隨機訪問return 0;
}

1.2 list

場景:存一條火車車廂編號,頻繁在中間插入/刪除

#include <iostream>
#include <list>
using namespace std;int main() {list<string> train = {"Car1", "Car3"};auto it = train.begin();++it;                          // 指向 "Car3"train.insert(it, "Car2");      // 在中間插入for (auto& c : train)cout << c << " ";          // 輸出:Car1 Car2 Car3 return 0;
}

1.3 deque

場景:實現一個簡單的滑動窗口

#include <iostream>
#include <deque>
using namespace std;int main() {deque<int> window;int nums[] = {1,2,3,4,5};for (int x : nums) {window.push_back(x);        // 新元素入隊if (window.size() > 3)      // 窗口大小保持 3window.pop_front();     // 彈出最舊元素cout << "當前窗口:";for (int y : window) cout << y;cout << endl;}return 0;
}

2. 關聯容器(Associative Containers)

2.1 set

場景:自動去重并升序存儲數字

#include <iostream>
#include <set>
using namespace std;int main() {set<int> s = {4, 2, 5, 2, 3};// 重復的 2 會自動去掉,元素自動排序cout << "排序后的唯一元素:";for (int x : s) cout << x << " ";  // 輸出:2 3 4 5return 0;
}

2.2 map

場景:模擬電話簿,用姓名查電話

#include <iostream>
#include <map>
using namespace std;int main() {map<string, string> phonebook;phonebook["Alice"] = "123-456";phonebook["Bob"]   = "987-654";cout << "Alice 的電話是:" << phonebook["Alice"] << endl;return 0;
}

3. 無序容器(Unordered Containers)

3.1 unordered_set

場景:快速檢測某元素是否出現過

#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_set<string> seen;string tokens[] = {"apple","banana","apple"};for (auto& t : tokens) {if (seen.count(t))cout << t << " 已出現過\n";else {cout << t << " 首次出現\n";seen.insert(t);}}return 0;
}

3.2 unordered_map

場景:統計字符串中每個字符的出現次數

#include <iostream>
#include <unordered_map>
using namespace std;int main() {string s = "banana";unordered_map<char,int> cnt;for (char c : s)cnt[c]++;for (auto& p : cnt)cout << p.first << " 出現了 " << p.second << " 次\n";return 0;
}

4. 容器適配器(Container Adapters)

4.1 stack

場景:檢查括號匹配

#include <iostream>
#include <stack>
using namespace std;bool isValid(string s) {stack<char> st;for (char c : s) {if (c == '(') st.push(c);else if (c == ')') {if (st.empty()) return false;st.pop();}}return st.empty();
}int main() {cout << (isValid("(()())") ? "匹配" : "不匹配") << endl;return 0;
}

4.2 queue

場景:打印機任務隊列,先進先出

#include <iostream>
#include <queue>
using namespace std;int main() {queue<string> jobs;jobs.push("doc1"); jobs.push("doc2");while (!jobs.empty()) {cout << "打印 " << jobs.front() << endl;jobs.pop();}return 0;
}

4.3 priority_queue

場景:任務調度,優先級高的先執行

#include <iostream>
#include <queue>
using namespace std;int main() {// 默認最大堆priority_queue<pair<int,string>> pq;pq.push({1,"低優先"}); pq.push({5,"高優先"});pq.push({3,"中優先"});while (!pq.empty()) {cout << pq.top().second << endl;pq.pop();}// 輸出:高優先 → 中優先 → 低優先return 0;
}

區分 set, multiset, map, multimap


1. set

  • 特點:自動排序、去重
  • 典型場景:提取一段文本中的不重復單詞并按字母序輸出
#include <iostream>
#include <set>
#include <sstream>
#include <string>
using namespace std;int main() {string text = "apple orange banana apple pear banana";istringstream iss(text);set<string> s;string w;while (iss >> w) {s.insert(w);  // 重復單詞只保留一個,自動按字母序排序}cout << "不重復單詞(按序):";for (const auto& word : s) {cout << word << " ";}// 輸出:banana apple orange pearreturn 0;
}

2. multiset

  • 特點:自動排序、允許重復
  • 典型場景:統計一組成績的分布(但還想保留原始次數順序)
#include <iostream>
#include <set>
using namespace std;int main() {multiset<int> scores = {85, 90, 78, 90, 85, 92};// 自動排序,但保留重復值cout << "所有成績(升序,含重復):";for (int sc : scores) {cout << sc << " ";}// 輸出:78 85 85 90 90 92return 0;
}

3. map

  • 特點:鍵唯一、自動排序 key → value
  • 典型場景:統計單詞出現頻率
#include <iostream>
#include <map>
#include <sstream>
#include <string>
using namespace std;int main() {string text = "apple banana apple pear banana apple";istringstream iss(text);map<string,int> freq;string w;while (iss >> w) {freq[w]++;  // key 不存在時自動插入,value 初始為 0}cout << "單詞頻率:\n";for (auto& p : freq) {cout << p.first << " -> " << p.second << "\n";}// 按字母序輸出:// apple -> 3// banana -> 2// pear -> 1return 0;
}

4. multimap

  • 特點:允許重復 key → value(一個 key 可對應多個 value)
  • 典型場景:一個人選修多門課程
#include <iostream>
#include <map>
#include <string>
using namespace std;int main() {multimap<string, string> courses;courses.insert({"Alice", "Math"});courses.insert({"Bob",   "Physics"});courses.insert({"Alice", "English"});courses.insert({"Bob",   "Chemistry"});// 遍歷所有同學及其課程cout << "選課列表:\n";for (auto& p : courses) {cout << p.first << " 選修 " << p.second << "\n";}// 如果只想看 Alice 的課程:cout << "\nAlice 的課程:\n";auto range = courses.equal_range("Alice");for (auto it = range.first; it != range.second; ++it) {cout << it->second << "\n";}// 輸出:// Math// Englishreturn 0;
}

通過這四個例子,你可以看到:

  • set:幫你去重并排序
  • multiset:排序但保留重復
  • map:唯一 key → 單一 value
  • multimap:同一個 key 下可有多個 value

區分 unordered_set, unordered_multiset, unordered_map, unordered_multimap

好的,我把每個容器的例子都寫得更詳細一些,涵蓋常用操作(插入、查找、刪除、遍歷等),并加上注釋說明。


1. unordered_set(無序不重復集合)

場景:記錄一段日志里出現過的錯誤代碼,只關心是否出現過

#include <iostream>
#include <unordered_set>
using namespace std;int main() {// 準備一段“錯誤碼”序列int errors[] = {101, 202, 303, 101, 404, 202, 505};// 定義 unordered_set 容器,記錄首次出現的錯誤碼unordered_set<int> seen;// 遍歷所有錯誤碼for (int code : errors) {// count 返回 0 或 1,表示容器里是否已有該元素if (seen.count(code)) {cout << "錯誤碼 " << code << " 已記錄過,跳過\n";} else {cout << "首次出現錯誤碼 " << code << ",記錄\n";seen.insert(code);  // 插入新元素}}cout << "\n最終記錄的錯誤碼有 " << seen.size() << " 個:";for (auto c : seen)             // 無序遍歷cout << c << " ";cout << endl;// 刪除某個錯誤碼int to_remove = 303;if (seen.erase(to_remove))      // erase 返回刪除的元素數量cout << "已刪除錯誤碼 " << to_remove << "\n";return 0;
}

要點

  • 插入:insert(val)
  • 查找:count(key)find(key)
  • 刪除:erase(key)
  • 遍歷:范圍 for(順序不固定)

2. unordered_multiset(無序可重復集合)

場景:統計商品售出記錄中各商品的銷售次數

#include <iostream>
#include <unordered_set>
using namespace std;int main() {// 假設售出商品 ID 列表int sales[] = {1001,1002,1001,1003,1002,1001,1004};// unordered_multiset 允許重復unordered_multiset<int> bag;// 插入所有售出記錄for (int id : sales) {bag.insert(id);}// 想知道某個商品賣了多少次int query = 1001;cout << "商品 " << query << " 共售出 "<< bag.count(query) << " 次。\n";// 遍歷所有記錄(會重復顯示)cout << "所有售出商品 ID(包含重復):";for (int id : bag)cout << id << " ";cout << endl;// 刪除一次售出記錄(只刪除一個實例)auto it = bag.find(query);if (it != bag.end()) {bag.erase(it);cout << "刪除一次 " << query << " 的記錄后,剩余 "<< bag.count(query) << " 次。\n";}return 0;
}

要點

  • 插入:insert(val)
  • 統計:count(key)
  • 查找一個實例:find(key)
  • 刪除單個實例:erase(iterator)erase(key)(后者會刪掉所有實例)

3. unordered_map(無序鍵→值映射)

場景:統計一段文字里每個單詞出現的次數,并支持查詢、刪除

#include <iostream>
#include <unordered_map>
#include <sstream>
using namespace std;int main() {string text = "apple orange banana apple pear banana";istringstream iss(text);// 定義字符到出現次數的映射unordered_map<string,int> freq;// 統計詞頻string w;while (iss >> w) {freq[w]++;  // 如果 key 不存在,會自動插入并初始化為 0}// 輸出所有詞頻cout << "詞頻統計:\n";for (auto& p : freq) {cout << p.first << " -> " << p.second << "\n";}// 查詢某個單詞string query = "banana";auto it = freq.find(query);if (it != freq.end()) {cout << query << " 出現了 " << it->second << " 次\n";} else {cout << query << " 沒出現過\n";}// 刪除某個單詞的統計freq.erase("pear");cout << "刪除 pear 后,剩余 " << freq.size() << " 個單詞記錄。\n";return 0;
}

要點

  • 插入/修改:operator[]emplace(key,val)
  • 查找:find(key)
  • 刪除:erase(key)erase(iterator)
  • 遍歷:for (auto& p : map)

4. unordered_multimap(無序鍵→多值映射)

場景:一個作者可能有多本書,要存儲“作者 → 書名”并支持查找、遍歷

#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;int main() {// 定義作者到書名的多映射unordered_multimap<string,string> library;library.emplace("Alice", "C++ Primer");library.emplace("Bob",   "Effective C++");library.emplace("Alice", "STL 源碼剖析");library.emplace("Bob",   "現代 C++ 設計");// 遍歷全部條目cout << "館藏列表:\n";for (auto& p : library) {cout << p.first << " 著《" << p.second << "》\n";}// 查找某位作者的所有書string author = "Alice";cout << "\n查詢 " << author << " 的作品:\n";auto range = library.equal_range(author);for (auto it = range.first; it != range.second; ++it) {cout << it->second << "\n";}// 刪除某本特定書(必須先找到對應 pair 的 iterator)for (auto it = range.first; it != range.second; ++it) {if (it->second == "C++ Primer") {library.erase(it);cout << "\n已刪除 Alice 的《C++ Primer》\n";break;}}return 0;
}

要點

  • 插入:emplace(key,val)insert({key,val})
  • 查找所有值:equal_range(key) 返回 [first, second)
  • 刪除單條記錄:erase(iterator)

分別介紹這八種關聯容器

一、有序關聯容器(紅黑樹,所有操作 O(log n))

1. std::set<Key, Compare, Alloc>

  • 鍵唯一,自動按 Compare 排序(默認 <)。
  • 典型接口
    • insert(k)emplace(k):插入元素
    • erase(it)erase(key):按迭代器或鍵刪除
    • find(key):查找,返回迭代器或 end()
    • count(key):鍵存在返回 1,否則 0
    • 范圍查詢:lower_bound(key)upper_bound(key)equal_range(key)
  • 遍歷保證從小到大。
#include <iostream>
#include <set>
using namespace std;int main() {set<int> s;// 插入s.insert(3);s.insert(1);s.emplace(2);      // 總共 {1,2,3}// 查找if (s.find(2) != s.end())cout << "Found 2\n";// 遍歷cout << "遍歷 set:";for (int x : s) cout << x << ' ';   // 1 2 3cout << endl;// 下界、上界auto lb = s.lower_bound(2);  // 指向 2auto ub = s.upper_bound(2);  // 指向 3// 刪除s.erase(1);   // 刪除鍵為1的元素cout << "刪除后大小:" << s.size() << endl;
}

2. std::multiset<Key, Compare, Alloc>

  • 允許重復鍵,其他與 set 相同。
  • 插入不會合并相同鍵;
  • 區間操作equal_range(key) 返回 [first, second)
#include <iostream>
#include <set>
using namespace std;int main() {multiset<string> ms;ms.insert("apple");ms.insert("banana");ms.insert("apple");  // 允許重復// 查看所有 "apple"auto range = ms.equal_range("apple");cout << "\"apple\" 出現次數:";for (auto it = range.first; it != range.second; ++it)cout << *it << ' ';cout << endl;  // apple apple// 刪除所有 "apple"ms.erase(range.first, range.second);cout << "刪除后大小:" << ms.size() << endl;
}

3. std::map<Key, T, Compare, Alloc>

  • 鍵唯一,每個鍵對應一個值。
  • 訪問
    • operator[](key):不存在則插入默認值并返回引用
    • at(key):不存在拋 out_of_range
  • 查找/刪除set
  • 遍歷按鍵升序,訪問 pair<const Key,T>
#include <iostream>
#include <map>
using namespace std;int main() {map<int, string> m;m[1] = "one";                 // 插入或修改m.insert({2, "two"});         // 插入// m[3] 默認插入 "",再賦值m[3] = "three";// 查找auto it = m.find(2);if (it != m.end())cout << "key=2, value=" << it->second << endl;// 范圍遍歷cout << "遍歷 map:\n";for (auto& [k,v] : m)cout << k << " → " << v << "\n";// 區間刪除 1 ≤ key < 3auto it1 = m.lower_bound(1);auto it3 = m.lower_bound(3);m.erase(it1, it3);cout << "刪除區間后大小:" << m.size() << endl;
}

4. std::multimap<Key, T, Compare, Alloc>

  • 允許重復鍵,其他同 map
  • 取相同鍵所有值equal_range(key)
#include <iostream>
#include <map>
using namespace std;int main() {multimap<int, string> mm;mm.emplace(1, "uno");mm.emplace(1, "ichi");mm.emplace(2, "dos");auto range = mm.equal_range(1);cout << "key=1 的所有值:";for (auto it = range.first; it != range.second; ++it)cout << it->second << ' ';cout << endl;// 刪除其中一個 pairauto it = range.first;mm.erase(it);cout << "刪除一個后剩余:" << mm.count(1) << " 個\n";
}

二、無序關聯容器(哈希表,平均 O(1),最壞 O(n))

1. std::unordered_set<Key, Hash, KeyEqual, Alloc>

  • 鍵唯一,底層是哈希桶+鏈表/開放尋址。
  • 常用接口
    • reserve(n):預留至少能放下 n 個元素
    • max_load_factor(f):設置最大負載因子
    • bucket_count()load_factor():查看當前桶數和負載
  • 查找/插入/刪除平均 O(1)。
#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_set<int> us;us.reserve(100);                   // 至少 100 個桶us.insert({3,1,4,1,5});            // 重復的1會被忽略cout << "元素:";for (int x : us) cout << x << ' '; // 無序輸出cout << endl;cout << "count(1)=" << us.count(1) << endl;  // 1 或 0us.erase(3);cout << "erase后 size=" << us.size() << endl;
}

2. std::unordered_multiset<Key, Hash, KeyEqual, Alloc>

  • 允許重復鍵,其他同 unordered_set
  • 獲取所有相同鍵equal_range(key)
#include <iostream>
#include <unordered_set>
using namespace std;int main() {unordered_multiset<int> ums;ums.insert(2);ums.insert(2);ums.insert(3);auto range = ums.equal_range(2);cout << "2 出現次數:";for (auto it = range.first; it != range.second; ++it)cout << *it << ' ';cout << endl;
}

3. std::unordered_map<Key, T, Hash, KeyEqual, Alloc>

  • 鍵唯一,哈希字典。
  • 訪問mapoperator[]at()
  • reserverehash 可控制性能。
#include <iostream>
#include <unordered_map>
using namespace std;int main() {unordered_map<string,int> um;um.reserve(50);um["apple"] = 3;um.emplace("banana", 2);cout << "apple 個數:" << um["apple"] << endl;if (um.find("cherry")==um.end())cout << "no cherry\n";// 自定義哈希和相等struct Point { int x,y; };struct PointHash { size_t operator()(Point const& p) const noexcept {return p.x*31 + p.y;}};struct PointEq { bool operator()(Point const& a, Point const& b) const noexcept {return a.x==b.x && a.y==b.y;}};unordered_map<Point,string,PointHash,PointEq> mp;mp[{1,2}] = "A";cout << mp[{1,2}] << endl;
}

4. std::unordered_multimap<Key, T, Hash, KeyEqual, Alloc>

  • 允許重復鍵,其他同 unordered_map
  • 取所有同鍵equal_range
#include <iostream>
#include <unordered_map>
using namespace std;int main() {unordered_multimap<int,string> umm;umm.emplace(1,"a");umm.emplace(1,"b");umm.emplace(2,"c");for (auto it = umm.equal_range(1).first; it != umm.equal_range(1).second; ++it)cout << it->second << ' ';cout << endl;
}

三、選型建議

  1. 需要排序/范圍查詢 → 選有序(set/map)。
  2. 追求最快查插且無需排序 → 選無序(unordered_*)。
  3. 是否允許重復鍵 → 普通版 vs. multi 版。
  4. 自定義排序/哈希 → 提供 CompareHash/KeyEqual

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/80134.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/80134.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/80134.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

2024沈陽區域賽,D - Dot Product Game

題目鏈接 樹狀數組求逆序對 #include<bits/stdc.h> using namespace std; using lllong long; typedef pair<int,int>PII; typedef priority_queue<int> upq; typedef priority_queue<int,vector<int>,greater<int>> dpq; const int M99…

簡易博客點贊系統實現

簡易博客點贊系統 好久沒寫 Java 了&#xff0c;整個簡單的項目進行康復訓練。 基于 Spring Boot SSM MySQL Mybatis-Plus Knife4j Swagger 的一個簡易博客點贊系統 開源地址&#xff1a;https://github.com/FangMoyu/simple-thumb 功能 登錄獲取當前登錄用戶獲取博客…

一個既簡單又詭異的問題

public class DaYaoGuai {static String s;public static void main(String[] args) {Thread t1 new Thread(){Overridepublic void run() {try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}s"深圳";}};t1.start();Thre…

使用docker在manjaro linux系統上運行windows和ubuntu

因為最近項目必須要使用指定版本的solidworks和maxwell&#xff08;都只能在win系統上使用&#xff09;, 且目前的ubuntu容器是沒有桌面的&#xff0c;導致我運行不了一些帶圖形的ros2功能。無奈之下&#xff0c;決定使用docker-compose寫一下配置文件&#xff0c;徹底解決問題…

Elasticsearch中的_source字段講解

_source 在 Elasticsearch 查詢中用于限制返回的字段,類似于 SQL 中的 SELECT 指定列。 代碼示例: esSearchResults = es_service.search_documents({"query": {"terms": {"file_id":

【論文閱讀20】-CNN-Attention-BiGRU-滑坡預測(2025-03)

這篇論文主要探討了基于深度學習的滑坡位移預測模型&#xff0c;結合了MT-InSAR&#xff08;多時相合成孔徑雷達干涉測量&#xff09;觀測數據&#xff0c;提出了一種具有可解釋性的滑坡位移預測方法。 [1] Zhou C, Ye M, Xia Z, et al. An interpretable attention-based deep…

C++ 的 IO 流

&#x1f4ac; &#xff1a;如果你在閱讀過程中有任何疑問或想要進一步探討的內容&#xff0c;歡迎在評論區暢所欲言&#xff01;我們一起學習、共同成長~&#xff01; &#x1f44d; &#xff1a;如果你覺得這篇文章還不錯&#xff0c;不妨順手點個贊、加入收藏&#xff0c;并…

spring cloud gateway前面是否必須要有個nginx

在 **"客戶端 → Nginx (前置限流) → Spring Cloud Gateway → 微服務(Sentinel 熔斷限流)"** 的架構中&#xff0c;**Spring Cloud Gateway 前面并不強制要求必須有 Nginx**&#xff0c;是否需要取決于具體場景。以下是詳細分析&#xff1a; 一、必須使用 Nginx 的…

Spark和Hadoop之間的對比和聯系

&#xff08;一&#xff09;Spark概述 Spark是一種基于內存的快速、通用、可拓展的大數據分析計算引擎。Hadoop是一個分布式系統基礎架構。 1&#xff09;官網地址&#xff1a;Apache Spark? - Unified Engine for large-scale data analytics 2&#xff09;文檔查看地址&…

多線程進階(Java)

注&#xff1a;此博文為本人學習過程中的筆記 1.常見的鎖策略 當我們需要自己實現一把鎖時&#xff0c;需要關注鎖策略。Java提供的synchronized已經非常好用了&#xff0c;覆蓋了絕大多數的使用場景。此處的鎖策略并不是和Java強相關的&#xff0c;只要涉及到并發編程&#…

c++STL——stack、queue、priority_queue的模擬實現

文章目錄 stack、queue、priority_queue的模擬實現使用部分模擬實現容器適配器deque的介紹原理真實結構deque的迭代器deque的操作deque的優缺點 stack的模擬實現按需實例化queue的模擬實現priority_queue的模擬實現為何引入仿函數代碼實現 stack、queue、priority_queue的模擬實…

【深度學習—李宏毅教程筆記】Transformer

目錄 一、序列到序列&#xff08;Seq2Seq&#xff09;模型 1、Seq2Seq基本原理 2、Seq2Seq模型的應用 3、Seq2Seq模型還能做什么&#xff1f; 二、Encoder 三、Decoder 1、Decoder 的輸入與輸出 2、Decoder 的結構 3、Non-autoregressive Decoder 四、Encoder 和 De…

C++鐫刻數據密碼的樹之銘文:二叉搜索樹

文章目錄 1.二叉搜索樹的概念2.二叉搜索樹的實現2.1 二叉搜索樹的結構2.2 二叉搜索樹的節點尋找2.2.1 非遞歸2.2.2 遞歸 2.3 二叉搜索樹的插入2.3.1 非遞歸2.3.2 遞歸 2.4 二叉搜索樹的刪除2.4.1 非遞歸2.4.2 遞歸 2.5 二叉搜索樹的拷貝 3.二叉樹的應用希望讀者們多多三連支持小…

系統架構設計師:流水線技術相關知識點、記憶卡片、多同類型練習題、答案與解析

流水線記憶要點? ?公式 總時間 (n k - 1)Δt 吞吐率 TP n / 總時間 → 1/Δt&#xff08;max&#xff09; 加速比 S nk / (n k - 1) | 效率 E n / (n k - 1) 關鍵概念 周期&#xff1a;最長段Δt 沖突?&#xff1a; ?數據沖突&#xff08;RAW&#xff09; → 旁路/…

強制重裝及驗證onnxruntime-gpu是否正確工作

#工作記錄 我們經常會遇到明明安裝了onnxruntime-gpu或onnxruntime后&#xff0c;無法正常使用的情況。 一、強制重新安裝 onnxruntime-gpu 及其依賴 # 強制重新安裝 onnxruntime-gpu 及其依賴 pip install --force-reinstall --no-cache-dir onnxruntime-gpu1.18.0 --extra…

桌面我的電腦圖標不見了怎么恢復 恢復方法指南

在Windows操作系統中&#xff0c;“我的電腦”或在較新版本中稱為“此電腦”的圖標&#xff0c;是訪問硬盤驅動器、外部存儲設備和系統文件的重要入口。然而&#xff0c;有些用戶可能會發現桌面上缺少了這個圖標&#xff0c;這可能是由于誤操作、系統設置更改或是不小心刪除造成…

2025.04.20【Lollipop】| Lollipop圖繪制命令簡介

Customize markers See the different options allowing to customize the marker on top of the stem. Customize stems See the different options allowing to customize the stems. 文章目錄 Customize markersCustomize stems Lollipop圖簡介R語言中的Lollipop圖使用ggp…

docker-compose搭建kafka

1、單節點docker-compose.yml version: 3 services:zookeeper:image: zookeeper:3.8container_name: zookeeperports:- "2181:2181"volumes:- ./data/zookeeper:/dataenvironment:ZOO_MY_ID: 1ZOO_MAX_CLIENT_CNXNS: 100kafka:image: bitnami/kafka:3.7container_na…

【問題】一招解決vscode輸出和終端不一致的困擾

背景&#xff08;閑話Trae&#xff09; Trae是挺好&#xff0c;用了幾天&#xff0c;發現它時不時檢查文件&#xff0c;一檢測就轉悠半天&#xff0c;為此我把當前環境清空&#xff0c;就留一個正在調的程序&#xff0c;結果還照樣檢測&#xff0c;雖然沒影響什么&#xff0c;…

Git,本地上傳項目到github

一、Git的安裝和下載 https://git-scm.com/ 進入官網&#xff0c;選擇合適的版本下載 二、Github倉庫創建 點擊右上角New新建一個即可 三、本地項目上傳 1、進入 要上傳的項目目錄&#xff0c;右鍵&#xff0c;選擇Git Bash Here&#xff0c;進入終端Git 2、初始化臨時倉庫…