用數組模擬棧實現遞歸函數模擬

做算法課設時候看到題目要求模擬函數遞歸時候棧的入棧出棧過程。本來想著直接調用系統遞歸函數即可,可是發現系統函數棧的空間非常小大約只有3000層,很容易爆棧。于是便有了用棧去模擬遞歸函數的想法,但是上網查了下貌似相關代碼比較少,讓GPT寫的代碼又牛頭不對馬嘴,于是手搓了一下。用棧模擬遞歸的過程,對遞歸過程,棧的理解都很有幫助。

在這里插入圖片描述

二分遞歸函數模擬

第一個函數erfen為正常的二分遞歸函數,但是系統的遞歸棧最多能遞歸到3000層左右,太少了。我們可以用棧來模擬函數遞歸的過程,這樣棧的層數可以達到我們設置的數組大小,我這里設置了二十萬。

#include <iostream>using namespace std;const int N = 2e5 + 5;struct binaryFrame {int l, r;int level;//記錄當前層數int step;//記錄步數
}stackBinary[N];/*需要模擬的二分遞歸函數
int erfen(int arr[], int l, int r, int key)
{int ans = -1;int mid = l + r >> 1;if (arr[mid] == key && l == r) return r;if (l >= r) return -1;if (arr[mid] >= key) {ans = erfen(arr, l, mid, key);}else {ans = erfen(arr, mid + 1, r, key);}return ans;
}
*/void binarySearch(int arr[], int l, int r, int key, int& index)
{int nowLevel = 1, nowStep = 0, tt = 0, L = l, R = r;tt++;stackBinary[tt] = { l,r,nowLevel,nowStep };cout << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";while (L < R){int mid = L + R >> 1;if (arr[mid] >= key){R = mid;stackBinary[++tt] = { L,R,++nowLevel,++nowStep };cout << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";}else {L = mid + 1;stackBinary[++tt] = { L,R,++nowLevel,++nowStep };cout << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";}}if (arr[R] == key) {index = R;}while (tt > 0){cout << "出棧:" << "當前執行函數紙帶范圍為:(" << stackBinary[tt].l << " , " << stackBinary[tt].r << " )" << " 層數為" << stackBinary[tt].level << " 執行步數為" << stackBinary[tt].step << "\n";tt--;}}int main()
{int arr[] = { 1,2,3,4,5,6,7,8,9,10 };int n = 10;int key = 2;int index = -1;binarySearch(arr, 0, n - 1, key, index);if (index == -1) {cout << "找不到這個吊數\n";}else {cout << "這個B數在數組中的第" << index + 1 << "個位置" << "\n";}return 0;
}

顯示壓棧出棧過程
在這里插入圖片描述

棧模擬回溯法解決01背包

#include<iostream>
#include<vector>using namespace std;typedef long long LL;const int N = 2e5 + 5;/*
// 全局變量用于存儲最終結果
int max_value = 0;
vector<int> best_set;/*
// 需要模擬的遞歸回溯函數
void knapsack(int index, int current_weight, int current_value, int capacity, const vector<int>& weights, const vector<int>& values, vector<int>& chosen_items) {// 基礎情況:如果考慮完所有物品if (index == weights.size()) {// 檢查當前物品集合是否是一個有效解if (current_weight <= capacity && current_value > max_value) {max_value = current_value;best_set = chosen_items;}return;}// 選擇當前物品chosen_items.push_back(index);knapsack(index + 1, current_weight + weights[index], current_value + values[index], capacity, weights, values, chosen_items);chosen_items.pop_back(); // 回溯// 不選擇當前物品knapsack(index + 1, current_weight, current_value, capacity, weights, values, chosen_items);
}*/struct backFrame
{int index;int current_weight;int current_value;int step;vector<int> chosenItems;int stage;
}stackBack[N];void backBag(int n, int capacity, int& max_value, vector<int>& weights, vector<int>& values, vector<int>& chosenItems, vector<int>& best_set)
{int tt = 0, nowStep = 0;stackBack[++tt] = { 0,0,0,0,{},0 };cout << "壓棧:初始化壓棧,壓入 0 0 0 0 {} 0" << "\n";while (tt > 0){backFrame now = stackBack[tt];cout << "當前執行函數層為:" << now.index << " " << now.current_weight << " " << now.current_value << " " << now.step << "\n";if (stackBack[tt].index >= n) {if (stackBack[tt].current_value > max_value && stackBack[tt].current_weight <= capacity){max_value = stackBack[tt].current_value;best_set = stackBack[tt].chosenItems;cout << "更新best_set ";for (auto i : best_set) cout << i + 1 << " ";cout << "\n";}tt--;cout << "出棧1:" << now.index  << " " << now.current_weight<< " " << now.current_value << " " << now.step << "\n";continue;}if (now.stage == 0) {//棧頂為初始狀態的話直接下一層函數壓棧chosenItems.push_back(now.index);stackBack[++tt] = { now.index + 1,now.current_weight + weights[now.index],now.current_value + values[now.index],now.step + 1,chosenItems,0 };cout << "壓棧1: " << now.index + 1 << " " << now.current_weight + weights[now.index] << " " << now.current_value + values[now.index] << " " << now.step + 1 << "\n";stackBack[tt - 1].stage ++;}else if (now.stage == 1) {chosenItems.pop_back();stackBack[++tt] = { now.index + 1,now.current_weight,now.current_value,now.step + 1,chosenItems,0 };cout << "壓棧2: " << now.index + 1 << " " << now.current_weight << " " << now.current_value  << " " << now.step + 1 << "\n";stackBack[tt - 1].stage ++;}else if (now.stage == 2) {tt--;cout << "出棧2:" << now.index  << " " << now.current_weight<< " " << now.current_value << " " << now.step << "\n";}}}int main()
{vector<int> weights = { 1,2,3,5,7,6 };vector<int> values = { 6,5,10,30,15,25 };vector<int> chosenItems;vector<int> best_set;int capacity = 10, n = 6;int max_value = -1;/*cout << "請輸入物品件數和背包容量\n";cin >> n >> capacity;cout << "請輸入" << n << "件物品,每件物品的質量,價值\n";for (int i = 0; i < n; i++){int x, y;cin >> x >> y;weights.push_back(x);values.push_back(y);}*/backBag(n, capacity, max_value, weights, values, chosenItems, best_set);LL sum = 0;for (auto i : best_set){cout << "選擇了第" << i + 1 << "件物品\n";sum += weights[i];}cout << "可以獲得的最大價值為" << max_value << "\n";cout << "所占用的背包空間為" << sum << "\n";return 0;
}/*
6 10
1 6
2 5
3 10
5 30
7 15
6 25
*/

在這里插入圖片描述

棧模擬備忘錄法解決01背包

#include <iostream>
#include <vector>
#include <cstring>
#include<Windows.h>using namespace std;const int N = 2e4 + 5;int n, W;int dp[505][1005]; // 備忘錄數組
vector<int> weights;
vector<int> values;/*需要模擬的備忘錄遞歸函數
// 遞歸函數,包含備忘錄算法邏輯,改為void類型
void knapsack(int idx, int W, int N, int& maxVal) {// 基本情況if (idx == N || W == 0) {maxVal = 0;cout << "邊界:" << idx << " " << W << " " << maxVal << "\n";return;}// 檢查是否已經計算過if (dp[idx][W] != -1) {maxVal = dp[idx][W];cout << "已經計算過:" << idx << " " << W << " " << maxVal << "\n";return;}// 選擇不包含當前物品knapsack(idx + 1, W, N, maxVal);int without = maxVal; // 從上一次遞歸中獲取結果cout << "without:" << idx << " " << W << " " << without << "\n";int with = 0;// 選擇包含當前物品,如果背包容量足夠if (W >= weight[idx]) {knapsack(idx + 1, W - weight[idx], N, with);with = values[idx] + with; // 添加當前物品的價值cout << "with:" << idx << " " << W << " " << with << "\n";}// 計算最大價值并存儲備忘錄結果maxVal = max(without, with);dp[idx][W] = maxVal; // 存儲備忘錄結果//cout<<"idx=,W=,dp= "<<idx<<" "<<W<<" "<<dp[idx]
}*/struct memoFrame
{int index;int with;int without;int max_value;int capacity;int stage;
}stackMemo[N];void memoBag(int index, int capacity, vector<int>& weights, vector<int>& values)
{int tt = 0;stackMemo[++tt] = { 0,0,0,0,capacity,0 };int max_value = 0;while (tt > 0){//cout << "cnt=" << cnt << "\n";memoFrame& now = stackMemo[tt];//cout << "當前函數層為,index,capacity,stage=" << now.index << " " << now.capacity << " " << now.stage << "\n";if ((now.index == n || now.capacity <= 0)) {memoFrame& last = stackMemo[tt - 1];last.max_value = 0;//cout << "當前層為:,返回給上一層的返回值為" << now.index << " " << now.capacity << " " << last.max_value << "\n";tt--;//cout << "出棧:index,capacity,return" << now.index << " " << now.capacity << " " << last.max_value << "\n";continue;}if (dp[now.index][now.capacity] != -1){memoFrame& last = stackMemo[tt - 1];last.max_value = dp[now.index][now.capacity];//cout << "當前層為:,返回給上一層的返回值為" << now.index << " " << now.capacity << " " << last.max_value << "\n";tt--;//cout << "出棧:index,capacity,return" << now.index << " " << now.capacity << " " << last.max_value << "\n";continue;}if (now.stage == 0){stackMemo[++tt] = { now.index + 1,0,0,0,now.capacity,0 };//cout << "壓棧0:" << now.index + 1 << " " << now.capacity << " " << "\n";now.stage++;}else if (now.stage == 1){now.without = now.max_value;//cout << "更新without:index, without:" << now.index << " " << now.without << "\n";now.stage++;}else if (now.stage == 2){if (now.capacity >= weights[now.index]) stackMemo[++tt] = { now.index + 1, 0, 0, 0, now.capacity - weights[now.index], 0 };// cout << "壓棧1:" << now.index + 1 << " " << now.capacity << " " << "\n";now.stage++;}else if (now.stage == 3){if (now.capacity >= weights[now.index]){now.with = now.max_value + values[now.index];//cout << "更新with, index,with:" << now.index << " " << now.with << "\n";}now.stage++;}else if (now.stage == 4){memoFrame& last = stackMemo[tt - 1];dp[now.index][now.capacity] = max(now.with, now.without);for (int i = 0; i < n; i++){for (int j = 0; j < W; j++){cout << dp[i][j] << " ";}cout << "\n";}last.max_value = dp[now.index][now.capacity];Sleep(1000);//cout << "更新dp: index,dp:" << now.index << " " << last.max_value << "\n";tt--;//cout << "出棧:index,capacity,return" << now.index << " " << now.capacity << " " << last.max_value << "\n";}}}int main() {cin >> n >> W;; // 讀取物品數量和背包容量weights.resize(n);values.resize(n);for (int i = 0; i < n; ++i) {cin >> weights[i] >> values[i];}memset(dp, -1, sizeof(dp));memoBag(0, W, weights, values);cout << "最大價值:" << dp[0][W] << endl;return 0;
}/*
6 10
1 6
2 5
3 10
5 30
7 15
6 25
*/

在這里插入圖片描述

把三個題整合到一塊

#include <iostream>
#include <vector>
#include <cstring>
#include<iomanip>
#include <windows.h>using namespace std;const int N = 2e4 + 5;typedef long long LL;int n, W;//n可以是二分的數組長度,也可以是背包的物品個數,W是背包容量int ansPos=-1;//二分搜索到的答案位置int arr[N];int dp[505][1005]; // 備忘錄數組
vector<int> weights;
vector<int> values;struct binaryFrame {int l, r;int level;//記錄當前層數int step;//記錄步數
}stackBinary[N];struct backFrame
{int index;int current_weight;int current_value;int step;vector<int> chosenItems;int stage;
}stackBack[N];struct memoFrame
{int index;int with;int without;int max_value;int capacity;int stage;
}stackMemo[N];void binarySearch(int l, int r, int key)
{int nowLevel = 1, nowStep = 0, tt = 0, L = l, R = r;tt++;stackBinary[tt] = { l,r,nowLevel,nowStep };cout<<right<<setw(50) << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";Sleep(200);while (L < R){int mid = L + R >> 1;if (arr[mid] >= key){R = mid;stackBinary[++tt] = { L,R,++nowLevel,++nowStep };cout<<right<<setw(50) << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";Sleep(200);}else {L = mid + 1;stackBinary[++tt] = { L,R,++nowLevel,++nowStep };cout<<right<<setw(50) << "壓棧:" << "當前執行函數紙帶范圍為:(" << L << " , " << R << " )" << " 層數為" << nowLevel << " 執行步數為" << nowStep << "\n";Sleep(200);}}if (arr[R] == key) {ansPos = R;}while (tt > 0){cout<<right<<setw(50) << "出棧:" << "當前執行函數紙帶范圍為:(" << stackBinary[tt].l << " , " << stackBinary[tt].r << " )" << " 層數為" << stackBinary[tt].level << " 執行步數為" << stackBinary[tt].step << "\n";Sleep(200);tt--;}}void backBag(int n, int capacity, int& max_value, vector<int>& weights, vector<int>& values, vector<int>& chosenItems, vector<int>& best_set)
{int tt = 0, nowStep = 0;stackBack[++tt] = { 0,0,0,0,{},0 };cout<<right<<setw(50) << "壓棧:初始化壓棧,壓入 0 0 0 0 {} 0" << "\n";Sleep(200);while (tt > 0){backFrame now = stackBack[tt];cout << right << setw(50) << "當前執行函數層為:下標為:" << now.index << " 當前重量:" << now.current_weight << " 當前價值:" << now.current_value << " 當前步數:" << now.step << "\n";Sleep(200);if (stackBack[tt].index >= n) {if (stackBack[tt].current_value > max_value && stackBack[tt].current_weight <= capacity){max_value = stackBack[tt].current_value;best_set = stackBack[tt].chosenItems;}tt--;cout<<right<<setw(50) << "出棧1:出棧下標:" << now.index << " 當前重量:" << now.current_weight << " 當前價值:" << now.current_value << " 當前步數:" << now.step << "\n";Sleep(200);continue;}if (now.stage == 0) {//棧頂為初始狀態的話直接下一層函數壓棧chosenItems.push_back(now.index);stackBack[++tt] = { now.index + 1,now.current_weight + weights[now.index],now.current_value + values[now.index],now.step + 1,chosenItems,0 };cout<<right<<setw(50) << "壓棧1: 壓棧下標:" << now.index + 1 << " 壓棧重量:" << now.current_weight + weights[now.index] << " 壓棧價值:" << now.current_value + values[now.index] << " 壓棧步數:" << now.step + 1 << "\n";Sleep(200);stackBack[tt - 1].stage++;}else if (now.stage == 1) {chosenItems.pop_back();stackBack[++tt] = { now.index + 1,now.current_weight,now.current_value,now.step + 1,chosenItems,0 };cout<<right<<setw(50) << "壓棧2: 壓棧下標:" << now.index + 1 << " 壓棧重量:" << now.current_weight << " " << now.current_value << " " << now.step + 1 << "\n";Sleep(200);stackBack[tt - 1].stage++;}else if (now.stage == 2) {tt--;cout<<right<<setw(50) << "出棧2:" << now.index << " 出棧重量:" << now.current_weight << " 出棧價值:" << now.current_value << " 出棧步數" << now.step << "\n";Sleep(200);}}}void memoBag(int index, int capacity, vector<int>& weights, vector<int>& values)
{int tt = 0;stackMemo[++tt] = { 0,0,0,0,capacity,0 };int max_value = 0;while (tt > 0){memoFrame& now = stackMemo[tt];cout<<right<<setw(50) << "當前函數層為,當前執行下標:" << now.index << " 當前背包剩余容量:" << now.capacity << " 當前stage:" << now.stage << "\n";Sleep(200);if ((now.index == n || now.capacity <= 0)) {memoFrame& last = stackMemo[tt - 1];last.max_value = 0;//cout << "當前層為:,返回給上一層的返回值為" << now.index << " " << now.capacity << " " << last.max_value << "\n";tt--;cout<<right<<setw(50) << "出棧:出棧下標:" << now.index << " 出棧時剩余背包容量:" << now.capacity << " 出棧返回值:" << last.max_value << "\n";Sleep(200);continue;}if (dp[now.index][now.capacity] != -1){memoFrame& last = stackMemo[tt - 1];last.max_value = dp[now.index][now.capacity];//cout << "當前層為:,返回給上一層的返回值為" << now.index << " " << now.capacity << " " << last.max_value << "\n";tt--;cout<<right<<setw(50) << "出棧:出棧下標:" << now.index << " 出棧時剩余背包容量:" << now.capacity << " 出棧時返回值:" << last.max_value << "\n";Sleep(200);continue;}if (now.stage == 0){stackMemo[++tt] = { now.index + 1,0,0,0,now.capacity,0 };cout<<right<<setw(50) << "壓棧0:壓棧下標:" << now.index + 1 << " 壓棧背包容量;" << now.capacity << " " << "\n";Sleep(200);now.stage++;}else if (now.stage == 1){now.without = now.max_value;//cout << "更新without:index, without:" << now.index << " " << now.without << "\n";now.stage++;}else if (now.stage == 2){if (now.capacity >= weights[now.index]) stackMemo[++tt] = { now.index + 1, 0, 0, 0, now.capacity - weights[now.index], 0 };cout<<right<<setw(50) << "壓棧1:壓棧下標:" << now.index + 1 << " 壓棧背包容量:" << now.capacity-weights[now.index] << " " << "\n";Sleep(200);now.stage++;}else if (now.stage == 3){if (now.capacity >= weights[now.index]){now.with = now.max_value + values[now.index];//cout << "更新with, index,with:" << now.index << " " << now.with << "\n";}now.stage++;}else if (now.stage == 4){memoFrame& last = stackMemo[tt - 1];dp[now.index][now.capacity] = max(now.with, now.without);last.max_value = dp[now.index][now.capacity];//cout << "更新dp: index,dp:" << now.index << " " << last.max_value << "\n";tt--;cout<<right<<setw(50) << "出棧:出棧下標:" << now.index << " 出棧時背包容量:" << now.capacity << " 這一層出棧的返回值:" << last.max_value << "\n";Sleep(200);}}}int main() 
{int op;cout<<right<<setw(50) << "請選擇要執行的遞歸函數模擬:1.二分搜索,2.回溯法,3.備忘錄法\n";while(cin >> op) {if (op == 1) {int key;cout << right << setw(50) << "棧模擬遞歸二分算法\n\n\n";cout << right << setw(50) << "請輸入查詢數組長度\n";cin >> n;cout << right << setw(50) << "請輸入" << n << "個數字\n";for (int i = 0; i < n; i++){cin >> arr[i];}cout << right << setw(50) << "請輸入需要查找的數字key\n";cin >> key;binarySearch(0, n - 1, key);if (ansPos == -1) cout << right << setw(50) << "找不到這個吊數\n";else cout << right << setw(50) << "數字" << key << "在數組中的第" << ansPos + 1 << "個位置\n";}else if (op == 2){weights.clear();values.clear();cout << right << setw(50) << "棧模擬遞歸回溯算法\n\n\n";cout << right << setw(50) << "請輸入物品件數和背包容量\n";cin >> n >> W;cout << right << setw(50) << "請輸入" << n << "件物品的質量和價值\n";for (int i = 0; i < n; i++){int x, y;cin >> x >> y;weights.push_back(x);values.push_back(y);}int max_value = -1;vector<int> best_set;vector<int> chosenItems;backBag(n, W, max_value, weights, values, chosenItems, best_set);cout << right << setw(50) << "可以獲得的最大價值為:" << max_value << "\n";for (auto i : best_set){cout << right << setw(50) << "選擇了第" << i + 1 << "件物品\n";}}else if (op == 3){weights.clear();values.clear();cout << right << setw(50) << "棧模擬遞歸備忘錄算法\n\n\n";cout << right << setw(50) << "請輸入物品件數和背包容量\n";cin >> n >> W;cout << right << setw(50) << "請輸入" << n << "件物品的質量和價值\n";for (int i = 0; i < n; i++){int x, y;cin >> x >> y;weights.push_back(x);values.push_back(y);}memset(dp, -1, sizeof(dp));memoBag(0, W, weights, values);cout << right << setw(50) << "能獲得的最大價值為:" << dp[0][W] << "\n";}cout << right << setw(50) << "1.繼續,2.結束\n";cin >> op;if (op == 2) break;cout << right << setw(50) << "請選擇要執行的遞歸函數模擬:1.二分搜索,2.回溯法,3.備忘錄法\n";}return 0;
}/*二分搜索樣例輸入
10
1 2 3 4 5 6 7 8 9 10
2
*//*回溯與備忘錄樣例輸入
6 10
1 6
2 5
3 10
5 30
7 15
6 25
*//*需要模擬的二分遞歸函數
int erfen(int arr[], int l, int r, int key)
{int ans = -1;int mid = l + r >> 1;if (arr[mid] == key && l == r) return r;if (l >= r) return -1;if (arr[mid] >= key) {ans = erfen(arr, l, mid, key);}else {ans = erfen(arr, mid + 1, r, key);}return ans;
}
*//*
// 需要模擬的遞歸回溯函數
void knapsack(int index, int current_weight, int current_value, int capacity, const vector<int>& weights, const vector<int>& values, vector<int>& chosen_items) {// 基礎情況:如果考慮完所有物品if (index == weights.size()) {// 檢查當前物品集合是否是一個有效解if (current_weight <= capacity && current_value > max_value) {max_value = current_value;best_set = chosen_items;}return;}// 選擇當前物品chosen_items.push_back(index);knapsack(index + 1, current_weight + weights[index], current_value + values[index], capacity, weights, values, chosen_items);chosen_items.pop_back(); // 回溯// 不選擇當前物品knapsack(index + 1, current_weight, current_value, capacity, weights, values, chosen_items);
}*//*需要模擬的備忘錄遞歸函數
// 遞歸函數,包含備忘錄算法邏輯,改為void類型
void knapsack(int idx, int W, int N, int& maxVal) {// 基本情況if (idx == N || W == 0) {maxVal = 0;cout << "邊界:" << idx << " " << W << " " << maxVal << "\n";return;}// 檢查是否已經計算過if (dp[idx][W] != -1) {maxVal = dp[idx][W];cout << "已經計算過:" << idx << " " << W << " " << maxVal << "\n";return;}// 選擇不包含當前物品knapsack(idx + 1, W, N, maxVal);int without = maxVal; // 從上一次遞歸中獲取結果cout << "without:" << idx << " " << W << " " << without << "\n";int with = 0;// 選擇包含當前物品,如果背包容量足夠if (W >= weight[idx]) {knapsack(idx + 1, W - weight[idx], N, with);with = values[idx] + with; // 添加當前物品的價值cout << "with:" << idx << " " << W << " " << with << "\n";}// 計算最大價值并存儲備忘錄結果maxVal = max(without, with);dp[idx][W] = maxVal; // 存儲備忘錄結果//cout<<"idx=,W=,dp= "<<idx<<" "<<W<<" "<<dp[idx]
}*/

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

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

相關文章

小馬搬運物品-第13屆藍橋杯省賽Python真題精選

[導讀]&#xff1a;超平老師的Scratch藍橋杯真題解讀系列在推出之后&#xff0c;受到了廣大老師和家長的好評&#xff0c;非常感謝各位的認可和厚愛。作為回饋&#xff0c;超平老師計劃推出《Python藍橋杯真題解析100講》&#xff0c;這是解讀系列的第89講。 小馬搬運物品&…

如何與Honda建立EDI連接?

你是本田Honda的新供應商&#xff0c;需要具備EDI電子數據交換功能嗎&#xff1f;在與本田Honda交換EDI消息時需要幫助嗎&#xff1f;本文將帶你快速了解Honda的EDI需求&#xff0c;明確EDI對接需要完成的工作。 項目背景 本田是一家世界領先的汽車制造商&#xff0c;在全球2…

倉庫選址問題【數學規劃的應用(含代碼)】阿里達院MindOpt

本文主要講述使用MindOpt工具優化倉庫選址的數學規劃問題。 視頻講解&#x1f448;&#x1f448;&#x1f448;&#x1f448;&#x1f448;&#x1f448;&#x1f448;&#x1f448;&#x1f448; 一、案例場景 倉庫選址問題在現代物流和供應鏈管理中具有重要的應用。因為倉庫…

《數據結構與算法基礎 by王卓老師》學習筆記——2.2線性表的案例引入

案例一&#xff1a;一元多項式的運算 案例二&#xff1a;稀疏多項式的運算 案例三&#xff1a;圖書信息管理系統 總結

【Leetcode】520. 檢測大寫字母

文章目錄 題目思路代碼復雜度分析時間復雜度空間復雜度 結果總結 題目 題目鏈接&#x1f517;我們定義&#xff0c;在以下情況時&#xff0c;單詞的大寫用法是正確的&#xff1a; 全部字母都是大寫&#xff0c;比如 “USA” 。單詞中所有字母都不是大寫&#xff0c;比如 “le…

Mybatis入門——語法詳解:基礎使用、增刪改查、起別名、解決問題、注釋、動態查詢,從入門到進階

文章目錄 1.基礎使用1.添加依賴2.在resouces文件下新建xml文件db.properties3.在resouces文件下新建xml文件mybatis-config-xml4.創建一個MybatisUtils工具類5.創建xml文件XxxMapper.xml映射dao層接口6.添加日志5.測試 2.增刪改查1.select2.delete3.update4.insert5.模糊查詢6.…

同心創建 共踐食安 | 趙夢澈榮獲食品安全大使

“民族要復興&#xff0c;鄉村必振興”&#xff0c;為深入貫徹落實國家鄉村振興戰略&#xff0c;推進鄉村全面振興不斷取得新成效&#xff0c;助力全國優質食品農產品的宣傳推廣、市場營銷、品牌創建工作&#xff0c;由中國食品安全報社主辦&#xff0c;商業發展中心、健康中國…

python數據分析與可視化一

公共部分 # 引入數據分析工具 Pandas import pandas as pd # 引入數據可視化工具 Matplotlib import matplotlib.pyplot as plt # 引入數據可視化工具 Seaborn (基于matplotlib) import seaborn as sns # 解決輸出時的列名對齊問題 pd.set_option(display.unicode.east_…

Python多線程編程詳解

Python多線程編程詳解 大家好&#xff0c;我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01; 多線程編程是利用計算機多核心和多線程處理器的優勢&#xff0c;提高程序并發性能的重要…

如何申請免費SSL證書以消除訪問網站顯示連接不安全提醒

在當今互聯網時代&#xff0c;網絡安全已成為一個不可忽視的問題。當用戶瀏覽一些網站時&#xff0c;有時會看到瀏覽器地址欄出現“不安全”的提示&#xff0c;這意味著該網站沒有安裝SSL證書&#xff0c;數據傳輸可能存在風險。那么&#xff0c;如何消除這種不安全提醒&#x…

2024年6月,Altair被Gartner魔力象限評為數據科學與機器學習平臺領導者

Altair 因其愿景完整性和執行能力被評為領導者 2024 年 6 月 20 日&#xff0c;Altair&#xff08;納斯達克股票代碼&#xff1a;ALTR&#xff09;宣布&#xff0c;Altair RapidMiner 被 Gartner Magic Quadrant?&#xff08;魔力象限&#xff09;評為數據科學與機器學習平臺領…

SpringBoot配置參數獲取

1、使用Value注解 import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class MyBean {Value("${myapp.name}") private String appName;public void printAppName() {System.out.print…

冪等生產者和事務生產者

Kafka消息交付 Kafka消息交付可靠性保障以及精確處理一次語義的實現。 所謂的消息交付可靠性保障&#xff0c;是指Kafka對Producer和Consumer要處理的消息提供什么樣的承諾。常見的承諾有以下三種&#xff1a; 最多一次&#xff08;atmost once&#xff09;&#xff1a;消息…

SpringBoot:SpringBoot 調用第三方接口的幾種方式

一、前言 在項目中調用第三方接口時&#xff0c;確實需要根據項目的技術棧、架構規范以及具體的業務需求來選擇最適合的調用方式。比如&#xff1a;RESTful API調用、Feign聲明式HTTP客戶端、Apache HttpClient等調用方式&#xff0c;每種方式都有其適用場景和優勢。下面我們就…

倉庫管理系統16--入庫管理

原創不易&#xff0c;打字不易&#xff0c;截圖不易&#xff0c;多多點贊&#xff0c;送人玫瑰&#xff0c;留有余香&#xff0c;財務自由明日實現。 1、創建物資入庫用戶控件 <UserControl x:Class"West.StoreMgr.View.InStoreView"xmlns"http://schema…

CAS自旋解析

CAS全稱CompareAndSwap(比較并交換)&#xff0c;是cpu的指令&#xff0c;調用時不涉及上下文的切換。Java中屬于樂觀鎖的一種&#xff0c;具體流程如下圖&#xff1a; 具體的實現使用的是Unsafe類去調用native修飾的compareAndSwap方法&#xff0c;4個字段分別是對象實例&#…

PTA—C語言期末復習(判斷題)

1. C語言程序是從源文件的第一條語句開始執行的 &#xff08;F&#xff09; 在 C 語言中&#xff0c;程序是從 main 函數開始執行的&#xff0c;而不是從源文件的第一條語句開始執行 2. 若變量定義為double x;&#xff0c;則x % 2是符合C語言語法的表達式 &#xff08;F&#…

通過nginx去除 api url前綴 并保持后面剩余的url不變向后臺請求

如 我前臺瀏覽器向后臺請求的接口是 http://127.0.0.1:5099/api/sample/sample/getbuttonlist 實際的請求接口傳向 http://192.168.3.71:5099/sample/sample/getbuttonlist 方法是向config中加入下面這樣一個server server {listen 5099;location /api/ {rewrite ^/a…

HTML流星雨

目錄 寫在前面 完整代碼 代碼分析 系列文章 寫在最后 寫在前面 歲月如梭&#xff0c;光陰似箭&#xff0c;不知不覺暑假就要來嘍&#xff0c;本期小編用HTML給大家手搓了一個炫酷的流星雨動畫&#xff0c;一起來看看吧。 完整代碼 <!DOCTYPE html> <html lang…

項目風險管理系統有哪些?分享11款主流項目管理系統

本文將分享11款主流項目管理系統&#xff1a;PingCode、Worktile、StandardFusion、MasterControl、ClickUp、SAI360、Netwrix Auditor、MetricStream、Wrike、Celoxis、Zoho Projects。 在項目管理中&#xff0c;風險管理不僅是一個挑戰&#xff0c;也是保證項目順利進行的關鍵…