博客主要記錄關於算法方面的知識(可能偏競賽方面),代碼均使用C++編寫,不包含基礎的語法介紹。ios
聽從寧繁勿簡、深刻淺出的原則,每篇文章都會配上例題,儘可能給出代碼,方便學習。c++
初學者入門數據結構與算法時,面對那麼多的平臺和題庫,可能無從下手,找不到一個系統學習的方法,也許這系列的文章能幫你係統的學到知識,有效的提升思惟與代碼水平😉。redis
推薦的OJ(在線評測系統)算法
若是你使用Visual Studio,而且沒有導入萬能頭,能夠繼續往下看安全
萬能頭文件涵蓋了作題中須要的大部分頭文件(在作題中我就沒遇到須要額外導入其餘頭文件的題😂)。其包含的頭文件較多,因此編譯的時間也會比較多,但不會影響運行時間。數據結構
萬能頭文件使用: #include <bits/stdc++.h>
dom
但在Visual Studio中沒法直接引用萬能頭,須要本身手動添加。函數
stdc++.h源碼:學習
// C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2014 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers #define _CRT_SECURE_NO_WARNINGS // C #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdalign> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> #endif
在Visual Studio中使用scanf之類的C語言內置函數會報錯,由於Visual Studio認爲這些函數不安全,應使用scanf_s之類的函數,但在代碼中加入 #define _CRT_SECURE_NO_WARNINGS
便可屏蔽這類的安全提示,畢竟咱們是寫算法的嘛。我已經把屏蔽安全提示的語句添加至上面的代碼中了,直接複製使用便可。優化
快速添加至Visual Studio的方法:
#include <bits/stdc++.h>
便可