随笔分类 - 基础算法
摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; bool cmp(vector<int>& A, vector<int>& B) { if (A.size() != B.size()) return A.size() >
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; int main() { double x; scanf("%lf", &x); double l = -1e5, r = 1e5; while (r - l > 1e-8) { double mid =
阅读全文
摘要:点击查看代码 #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;
阅读全文
摘要:点击查看代码 #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 >=
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #include <iostream> #include <algorithm> using namespace std; const int N = 1e5 + 10; struct Data { int x; double y; string z; bool operator< (
阅读全文
摘要:点击查看代码 class Solution { public: int NumberOf1(int n) { unsigned un = n; int res = 0; while (un) { res += un & 1; un >>= 1; } return res; } }; 首先将 n 转化
阅读全文
摘要:堆排序 点击查看代码 class Solution { public: vector<int> getLeastNumbers_Solution(vector<int> input, int k) { priority_queue<int> heap; for (auto x : input) {
阅读全文
摘要:点击查看代码 class Solution { public: void reOrderArray(vector<int> &array) { int i = 0, j = array.size() - 1; while (i < j) { while (i <= j && array[i] % 2
阅读全文
摘要:点击查看代码 class Solution { public: int getMissingNumber(vector<int>& nums) { if (nums.empty()) return 0; int l = 0, r = nums.size(); while (l < r) { int
阅读全文
摘要:点击查看代码 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
阅读全文
摘要:点击查看代码 #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(
阅读全文
摘要:点击查看代码 #include<iostream> #include<algorithm> using namespace std; string a, b; int main() { cin >> a >> b; if (a.size() < b.size()) swap(a, b); for (
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; string str, res; int main() { while (cin >> str) { if (str.back() == '.') str.pop_back(); if (str.size(
阅读全文
摘要:点击查看代码 #include<iostream> #include<sstream> using namespace std; string s, a ,b; int main() { getline(cin ,s); cin >> a >> b; stringstream ssin(s); st
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #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
阅读全文