主頁 > 作業系統 > 如何最大化n個正整數的GCD,并且從代表它們的序列中移除最少數量?

如何最大化n個正整數的GCD,并且從代表它們的序列中移除最少數量?

2022-01-24 10:37:05 作業系統

我正在嘗試解決一項競爭性編程任務,但我找不到有效的解決方案來解決最后 5 個測驗用例。

您會收到 t (t >= 1 && t <= 5) 查詢,每個查詢由 n 個數字 num (num >= 1 && num <= 1000000) 組成。代表每個查詢的序列沒有排序,其中可以有重復的數字。所有 ns 的總和小于 1000000。讓我們將單個查詢中所有數字的 GCD 稱為 x。任務是找出為了使 x 最大化而必須進行的最小移除次數。時間限制為 0.7 秒。

考慮到這個 (8, 2, 6, 4, 10, 12) 是給我的詢問。GCD (8, 2, 6, 4, 10, 12) = 2 但如果我移除 2、6 和 10 GCD (8, 4, 12) = 4。我將初始 GCD x 從 2 增加到 4,移除 3 次即 2 , 6 和 10。這個問題的答案是 3。

到目前為止,我提出的最好的想法如下:

#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <limits>
#include <algorithm>
#include <iterator>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin >> t;
    int i, n, tmp, j, num, div, max, min, rem;
    std::vector<int> ans;
    for (i = 0; i != t;   i) {
        std::cin >> n;
        tmp = 0;
        std::map<int, int> buckets;
        for (j = 0; j != n;   j) {
            std::cin >> num;
            tmp = std::gcd(tmp, num);
            for (div = 1; div * div <= num;   div) {
                if (num % div == 0) {
                      buckets[div];
                    if (div * div != num) {
                          buckets[num / div];
                    }
                }
            }
        }
        max = tmp;
        min = std::numeric_limits<int>::max();
        for (auto const& elem : buckets) {
            if (elem.second != n && elem.first > max) {
                rem = n - elem.second;
                if (rem < min) {
                    max = elem.first;
                    min = rem;
                }
            }
        }
        ans.emplace_back(min);
    }
    std::copy(ans.cbegin(), std::prev(ans.cend()),
        std::ostream_iterator<int>(std::cout, "\n"));
    std::cout << ans.back() << '\n';
    return 0;
}

我正在計算 x (tmp) 并將每個數字 (num) 拆分為其除數 (div)。我不斷更新存盤桶,這是一個 std::map<div,該 div 可以劃分的特定查詢 t 中的數字計數>。我遍歷存盤桶并找出哪個是大于 max (x) 的除數 (elem.first),同時導致最小數量的移除。

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <limits>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin >> t;
    int i, n, tmp_gcd, tmp_max, j, num,
        ans, k, tmp_sum, l, tmp_min;
    for (i = 0; i != t;   i) {
        std::cin >> n;
        std::vector<int> inq_db;
        inq_db.reserve(n);
        tmp_max = tmp_gcd = 0;
        for (j = 0; j != n;   j) {
            std::cin >> num;
            inq_db.emplace_back(num);
            tmp_gcd = std::gcd(tmp_gcd, num);
            tmp_max = std::max(tmp_max, num);
        }
        std::vector<int> buckets(tmp_max   1);
        for (auto const& elem : inq_db) {
              buckets[elem];
        }
        ans = std::numeric_limits<int>::max();
        for (k = tmp_gcd   1; k <= tmp_max;   k) {
            tmp_sum = 0;
            for (l = k; l <= tmp_max; l  = k) {
                tmp_sum  = buckets[l];
            }
            tmp_min = n - tmp_sum;
            if (tmp_min != n && tmp_min < ans) {
                ans = tmp_min;
            }
        }
        std::cout << ans << '\n';
    }
    return 0;
}

I’m calculating x (tmp_gcd) and finding out maximum value of num (tmp_max) in the inquiry t that I’m working with. I initialize buckets with max 1 zeroes (counters). I do this in order to avoid initializing buckets with 1000000 counters each time. Instead of splitting the number into its divisors I’m using the counters in buckets to count the numbers that are equal to their index. 5th element in buckets is counting how many numbers with the value 5 I have in the inquiry, 100th element – value 100 and so on. I loop through buckets starting from index x 1 and find out how many numbers with GCD = k I have in buckets. The idea here is that numbers k, 2k, 3k, 4k, 5k and so on have GCD = k. I find out which is the number (ans) that leads to minimum number of removals.

The problem with both my ideas is that they are given with time limit exceeded on the last 5 test cases. I need some help to optimize them or If this is not possible to be given a new one. Thanks in advance for your time.

@Damien I reworked your logic this way:

#include <iostream>
#include <map>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>

std::vector<int> split(int num) {
    std::vector<int> ret;
    if ((num & 1) == 0) {
        ret.emplace_back(2);
        do {
            num >>= 1;
        } while ((num & 1) == 0);
    }
    int div, div_lim;
    for (div = 3, div_lim = static_cast<int>(std::sqrt(num)); div <= div_lim; div  = 2) {
        if (num % div == 0) {
            ret.emplace_back(div);
            do {
                num /= div;
            } while (num % div == 0);
            div_lim = static_cast<int>(std::sqrt(num));
        }
    }
    if (num != 1) {
        ret.emplace_back(num);
    }
    return ret;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin >> t;
    int i, n, x, j, num, ans;
    std::map<int, int>::const_iterator it;
    for (i = 0; i != t;   i) {
        std::cin >> n;
        std::vector<int> seq;
        seq.reserve(n);
        x = 0;
        for (j = 0; j != n;   j) {
            std::cin >> num;
            seq.emplace_back(num);
            x = std::gcd(x, num);
        }
        if (x != 1) {
            for (auto& elem : seq) {
                elem /= x;
            }
        }
        std::map<int, int> lookup;
        for (auto const& elem : seq) {
            auto ret = split(elem);
            for (auto const& div : ret) {
                  lookup[div];
            }
        }
        it = std::max_element(lookup.cbegin(), lookup.cend(),
            [](std::pair<const int, int> const& lhs, std::pair<const int, int> const& rhs) {
                return lhs.second < rhs.second;
            });
        ans = n - it->second;
        std::cout << ans << '\n';
    }
    return 0;
}

but sadly I hit TLE on the last 5 test cases.

@TonyK It is in Bulgarian because the task is given on a Bulgarian competitive programming competition.

If I have this (4 6 8 10 12 14) test GCD is 2. Now let's split each number into its divisors:

4 (1, 2, 4)

6 (1, 2, 3, 6)

8 (1, 2, 4, 8)

10 (1, 2, 5, 10)

12 (1, 2, 3, 4, 6, 12)

14 (1, 2, 7, 14)

The candidates for GCD > 2 are the following ones:

14->I have to remove all the numbers but 14->5 removals

12->I have to remove all the numbers but 12->5 removals

10->I have to remove all the numbers but 10->5 removals

8->I have to remove all the numbers but 8->5 removals

7->I have to remove all the numbers but 14->5 removals

6->I have to remove 4, 8, 10 and 14->4 removals

5->I have to remove all the numbers but 10->5 removals

4->I have to remove 6, 10 and 14->3 removals

3->I have to remove 4, 8, 10 and 14->4 removals

The answer is 3 removals and they can be achieved at GCD = 4.

uj5u.com熱心網友回復:

這是一個相當快速的解決方案。

第一步包括計算全域 gcd 并將所有數字除以它。

全域 GCD 現在等于 1。現在的問題是找到最小的移除次數,使得這個 GC 不再等于 1。

為此,我們對每個數字進行素數分解,并找到其中最常見的素數。

結果是陣列大小減去這個素數出現的次數。

復雜性由素數分解決定:O(n sqrt(m)),其中m是最大資料值。

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <limits>
#include <map>
#include <cmath>

//  For test
void print (const std::vector<int> &v) {
        for (auto &x: v) {
                std::cout << x << " ";
        }
        std::cout << std::endl;
}

//  Get the prime factors of a number (multiplicity is not important here)

std::vector<int> get_primes (int n) {
    int n_sav = n;
    if (n <= 1) return {};
    std::vector<int> primes;

    if (n % 2 == 0) {
        primes.push_back(2);
        n /= 2;
        while (n%2 == 0) {n /= 2;}
    }
    int max_prime = sqrt(n);
    int p = 3;
    while (p <= max_prime) {
        if (n % p == 0) {
            primes.push_back(p);
            n/= p;
            while (n%p == 0) {n /= p;}
            max_prime = sqrt(n);
        }
        p  = 2;
    }
    if (n != 1) {
        primes.push_back(n);
    }
    //std::cout << n_sav << ": ";
    //print (primes);
    return primes;
}


int min_removals (std::vector<int>& numbers) {
    int n = numbers.size();
    if (n == 1) return -1;
    int current_gcd = numbers[0];
    for (int i = 1; i < n;   i) current_gcd = std::gcd (current_gcd, numbers[i]);
    std::cout << "current GCD = " << current_gcd << "\n";
    if (current_gcd != 1) {
        for (int i = 0; i < n;   i) numbers[i] /= current_gcd;
    }
    std::map<int, int> list_primes;
    for (auto x: numbers) {
        auto primes = get_primes(x);
        for (int i: primes) {
            list_primes[i]  ;
        }
    }
    int most_frequent = 0;
    for (const auto& p: list_primes) {
        if (p.second > most_frequent) {
            most_frequent = p.second;
        }
    }
    
    return n - most_frequent;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin >> t;
    while (t--) {
        int n;
        std::cin >> n;
        std::vector<int> numbers (n);
        for (int i = 0; i < n;   i) {
            std::cin >> numbers[i];
        }
        auto ans = min_removals (numbers);
        std::cout << ans << "\n";
    }
    return 0;
}

使用以下變體,通過在主函式中加入素數分解,速度略有提高。這避免了一些無用的資料副本。看來收益不可小覷。

int min_removals_new (std::vector<int>& numbers) {
    int n = numbers.size();
    if (n == 1) return -1;
    int current_gcd = numbers[0];
    for (int i = 1; (i < n) && (current_gcd > 1);   i) current_gcd = std::gcd (current_gcd, numbers[i]);
    if (current_gcd != 1) {
        for (int i = 0; i < n;   i) numbers[i] /= current_gcd;
    }
    std::map<int, int> list_primes;
    
    for (auto x: numbers) {
        if (x == 1) continue;
        if (x % 2 == 0) {
            list_primes[2]  ;
            x /= 2;
            while (x%2 == 0) {x /= 2;}
        }
        int max_prime = sqrt(x);
        int p = 3;
        while (p <= max_prime) {
            if (x % p == 0) {
                list_primes[p]  ;
                x/= p;
                while (x%p == 0) {x /= p;}
                max_prime = sqrt(x);
            }
            p  = 2;
        }
        if (x != 1) {
            list_primes[x]  ;
        }
    }
       
    int most_frequent = 0;
    for (const auto& p: list_primes) {
        if (p.second > most_frequent) {
            most_frequent = p.second;
        }
    }
    
    return n - most_frequent;
}

uj5u.com熱心網友回復:

我終于找到了足夠快(550-600 ms)的解決方案!

#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <algorithm>
#include <memory>
#include <bitset>
#include <unordered_map>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    std::cin >> t;
    int i, n, j, num, lim = 0, max, div, cpy, ans;
    std::vector<int> ns, gcds(t);
    std::vector<std::vector<int>> db(t);
    std::vector<int>::const_iterator it;
    std::pair<decltype(it), decltype(it)> ret;
    for (i = 0; i != t;   i) {
        std::cin >> n;
        ns.emplace_back(n);
        db[i].reserve(n);
        for (j = 0; j != n;   j) {
            std::cin >> num;
            db[i].emplace_back(num);
            gcds[i] = std::gcd(gcds[i], num);
            lim = std::max(lim, num);
        }
        if (gcds[i] != 1) {
            for (auto& elem : db[i]) {
                elem /= gcds[i];
            }
        }
        std::sort(db[i].begin(), db[i].end());
    }
    auto primes = std::make_unique<std::bitset<10000000   1>>();
    primes->set();
    primes->set(0, false);
    primes->set(1, false);
    for (i = 2; i * i <= lim;   i) {
        if (primes->test(i)) {
            for (j = i * i; j <= lim; j  = i) {
                primes->set(j, false);
            }
        }
    }
    for (i = 0; i != t;   i) {
        std::unordered_map<int, int> lookup;
        max = 0;
        for (it = db[i].cbegin(); it != db[i].cend(); it = ret.second) {
            ret = std::equal_range(it, db[i].cend(), *it);
            if (primes->test(*it)) {
                lookup[*it]  = ret.second - ret.first;
                if (lookup[*it] > max) {
                    max = lookup[*it];
                }
                continue;
            }
            for (div = 2, cpy = *it; div * div <= cpy;   div) {
                if (cpy % div == 0) {
                    lookup[div]  = ret.second - ret.first;
                    if (lookup[div] > max) {
                        max = lookup[div];
                    }
                    do {
                        cpy /= div;
                    } while (cpy % div == 0);
                }
            }
            if (cpy != 1) {
                lookup[cpy]  = ret.second - ret.first;
                if (lookup[cpy] > max) {
                    max = lookup[cpy];
                }
            }
        }
        ans = ns[i] - max;
        std::cout << ans << '\n';
    }
    return 0;
}

我閱讀了所有 t 個查詢并將它們的 nums 存盤在一個由 t 個向量組成的大向量中,每個向量由 n 個元素組成。在讀取和存盤 db[i] 中的 nums 時,我將每個 n 存盤在向量 ns 中,計算特定查詢 gcds[i] 的 gcd 并找出最大 num lim。當我完成閱讀階段時,我將 db[i] 中的所有 nums 劃分為 gcds[i] 以便將 gcds[i] 從最終計算中排除。我對 db[i] 進行排序是為了避免對其中的重復數字進行質數分解。基于 lim 我找出范圍內的所有素數 [2; lim] 使用我通過 unique_ptr 素數存盤在堆中的位集。我使用 unordered_map 查找處理每個查詢 db[i]。使用 for 回圈和 equal_range 演算法,我跳到 db[i] 中的 nums 上,只對重復的第一個進行素數分解。例如,如果我有 7 7 7 7 7 7 7 13 17 19 ... ret.first 將指向第一個 7,而 ret.second 將指向 13。因為 7 已經是一個素數(我使用 bitset primes 進行檢查) 我不會將它分解為素數,我將遞增它的計數器 ret.second - ret.first 次,并將該計數器與表示 db[i] 中最頻繁 num 的計數的 max 進行比較。如果需要,我通過分配更新最大值。如果 *it 不是素數,我將使用下一個帶有 div 和 cpy 的 for 回圈對其進行素數分解。如果我遇到像 6 這樣的數字,它不能使用第一個 for 回圈完全分解,我將在它之后使用 If 子句,因為第一次迭代會發現 2 作為 6 的主要因素之一,然后我們將失敗3 它必須增加它的計數器。這就是 if 子句的目的。當我找出 db[i] 中最常見的 num 時,我只需從 ns[i] 中減去它的計數,從而找出為了改進 gcds[i] 而必須進行的最小洗掉次數最多。我輸出ans,就是這樣。

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/420165.html

標籤:

上一篇:使用遞回回溯。為什么代碼有效

下一篇:當工人多于作業時如何使用匈牙利演算法以及如何將作業的副本鏈接回原始?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more