随笔分类 -  基础算法

摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; bool cmp(vector<int>& A, vector<int>& B) { if (A.size() != B.size()) return A.size() > 阅读全文
posted @ 2022-04-25 21:04 wKingYu 阅读(29) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; vector<int> add(vector<int>& A, vector<int>& B) { vector<int> C; int t = 0; for (int i 阅读全文
posted @ 2022-04-25 20:12 wKingYu 阅读(31) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; int main() { double x; scanf("%lf", &x); double l = -1e5, r = 1e5; while (r - l > 1e-8) { double mid = 阅读全文
posted @ 2022-04-25 00:18 wKingYu 阅读(24) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0; i < n; 阅读全文
posted @ 2022-04-25 00:03 wKingYu 阅读(37) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; typedef long long ll; const int N = 1e5 + 10; int a[N], tmp[N]; ll merge_sort(int l, int r) { if (l >= 阅读全文
posted @ 2022-04-24 17:36 wKingYu 阅读(23) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include <iostream> using namespace std; const int N = 1e6 + 10; int a[N], tmp[N]; void merge_sort(int l, int r) { if (l >= r) return; int mid 阅读全文
posted @ 2022-04-24 17:02 wKingYu 阅读(18) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N]; int quick_select(int l, int r, int k) { if (l >= r) return a[l]; int 阅读全文
posted @ 2022-04-23 23:16 wKingYu 阅读(19) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include <iostream> #include <algorithm> using namespace std; const int N = 1e5 + 10; struct Data { int x; double y; string z; bool operator< ( 阅读全文
posted @ 2022-04-23 22:59 wKingYu 阅读(39) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 class Solution { public: int NumberOf1(int n) { unsigned un = n; int res = 0; while (un) { res += un & 1; un >>= 1; } return res; } }; 首先将 n 转化 阅读全文
posted @ 2022-04-23 22:46 wKingYu 阅读(33) 评论(0) 推荐(0) 编辑
摘要:堆排序 点击查看代码 class Solution { public: vector<int> getLeastNumbers_Solution(vector<int> input, int k) { priority_queue<int> heap; for (auto x : input) { 阅读全文
posted @ 2022-04-23 17:54 wKingYu 阅读(17) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 class Solution { public: void reOrderArray(vector<int> &array) { int i = 0, j = array.size() - 1; while (i < j) { while (i <= j && array[i] % 2 阅读全文
posted @ 2022-04-23 17:41 wKingYu 阅读(28) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 class Solution { public: int getMissingNumber(vector<int>& nums) { if (nums.empty()) return 0; int l = 0, r = nums.size(); while (l < r) { int 阅读全文
posted @ 2022-04-23 13:00 wKingYu 阅读(23) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 class Solution { public: int strToInt(string str) { int k = 0; while (k < str.size() && str[k] == ' ') k++; long long res = 0; int minus = 1; i 阅读全文
posted @ 2022-04-21 23:11 wKingYu 阅读(20) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; int n, ans = 0; void f(int k) { if (k == n) ans ++; else if (k < n) { f(k + 1); f(k + 2); } } int main( 阅读全文
posted @ 2022-04-15 13:08 wKingYu 阅读(48) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> #include<algorithm> using namespace std; string a, b; int main() { cin >> a >> b; if (a.size() < b.size()) swap(a, b); for ( 阅读全文
posted @ 2022-04-14 12:47 wKingYu 阅读(41) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; string str, res; int main() { while (cin >> str) { if (str.back() == '.') str.pop_back(); if (str.size( 阅读全文
posted @ 2022-04-14 12:09 wKingYu 阅读(25) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> #include<sstream> using namespace std; string s, a ,b; int main() { getline(cin ,s); cin >> a >> b; stringstream ssin(s); st 阅读全文
posted @ 2022-04-14 10:41 wKingYu 阅读(33) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; string a, b; int main() { getline(cin, a); getline(cin, b); for (char& c : a) c = tolower(c); for (char 阅读全文
posted @ 2022-04-13 23:24 wKingYu 阅读(39) 评论(0) 推荐(1) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 110; int n, m; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; int x = 0, y = 0, d = 1, q 阅读全文
posted @ 2022-04-13 20:28 wKingYu 阅读(31) 评论(0) 推荐(0) 编辑
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e6 + 10; int n; int a[N]; void quick_sort(int l, int r) { if (l >= r) return; int i = l 阅读全文
posted @ 2022-04-13 15:13 wKingYu 阅读(27) 评论(0) 推荐(1) 编辑

欢迎阅读『基础算法』
点击右上角即可分享
微信分享提示