04 2022 档案
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e6 + 10; int a[N], q[N]; int main() { int n, k; scanf("%d %d", &n, &k); for (int i = 0;
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int stk[N], tt = 0; int main() { int n; scanf("%d", &n); while (n --) { int x;
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int q[N]; int l = 0, r = 0; void push(int x) { q[r] = x; r ++; } void pop() { l
阅读全文
摘要:点击查看代码 #include<iostream> #include<stack> #include<cstring> #include<unordered_map> using namespace std; stack<int> nums; stack<char> op; unordered_ma
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int s[N], idx = 0; void push(int x) { s[idx] = x; idx ++; } void pop() { idx --
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int e[N], r[N], l[N]; int idx; void init() { r[0] = 1; l[1] = 0; idx = 2; } voi
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int head, idx; int e[N], ne[N]; void init() { head = -1; idx = 0; } void add_to
阅读全文
摘要:点击查看代码 #include<iostream> #include<vector> #include<algorithm> using namespace std; typedef pair<int, int> PII; vector<PII> segs; void merge(vector<PI
阅读全文
摘要:点击查看代码 #include<iostream> #include<vector> #include<algorithm> using namespace std; typedef pair<int, int> PII; const int N = 3e5 + 10; vector<int> al
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; int lowbit(int x) { return x & -x; } int main() { int n; scanf("%d", &n); while (n --) { int x; scanf("
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], b[N]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0;
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], b[N]; int main() { int n, m, x; scanf("%d %d %d", &n, &m, &x); for (i
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], s[N]; int main() { int n, res = 0; scanf("%d", &n); for (int i = 0; i
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e3 + 10; int a[N][N], b[N][N]; void insert(int x1, int y1, int x2, int y2, int c) { b[x1
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], b[N]; void insert(int l, int r, int c) { b[l] += c; b[r + 1] -= c; }
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e3 + 10; int a[N][N], s[N][N]; int main() { int n, m, q; scanf("%d %d %d", &n, &m, &q);
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; const int N = 1e5 + 10; int a[N], s[N]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1;
阅读全文
摘要:点击查看代码 #include<iostream> #include<vector> #include<algorithm> using namespace std; vector<int> div(vector<int>& A, int b, int &r) { vector<int> C; fo
阅读全文
摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; vector<int> mul(vector<int>& A, int b) { vector<int> C; int t = 0; for (int i = 0; i <
阅读全文
摘要:点击查看代码 #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<vector<int>> res; vector<vector<int>> permutation(vector<int>& nums) { sort(nums.begin(), nums.end()); do { res
阅读全文
摘要:点击查看代码 class Solution { public: vector<int> findNumbersWithSum(vector<int>& nums, int target) { unordered_set<int> hash; for (int i = 0; i < nums.size
阅读全文
摘要:堆排序 点击查看代码 class Solution { public: vector<int> getLeastNumbers_Solution(vector<int> input, int k) { priority_queue<int> heap; for (auto x : input) {
阅读全文
摘要:点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla
阅读全文
摘要:点击查看代码 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
阅读全文
摘要:
阅读全文
摘要:可以用 if ( a.find(x) == a.end() ) 判断 x 在 a 中是否存在
阅读全文
摘要:
阅读全文
摘要:在出栈时需要进行两步操作,即先 top( ) 获得栈顶元素,再 pop( ) 删除栈顶元素
阅读全文
摘要:
阅读全文
摘要:点击查看代码 #include<iostream> #include<vector> using namespace std; int main() { // 初始化 a 为 1, 2, 3 vector<int> a({1, 2, 3}); // 也可以是 vector<int> a {1, 2,
阅读全文
摘要:点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla
阅读全文
摘要:点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla
阅读全文
摘要:迭代版本 点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *
阅读全文
摘要:点击查看代码 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
阅读全文
摘要:点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla
阅读全文
摘要:点击查看代码 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ cla
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; int n, m, ans = 0; void dfs(int x, int y) { if (x == n && y == m) ans ++; else { if (y < m) dfs(x, y +
阅读全文
摘要:点击查看代码 #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> using namespace std; const int N = 200; string str[N]; int n ; int main() { while (cin >> n, n) { int len = 1000; for (int i
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; string s, s1, s2; int main() { char c; while (cin >> c, c != ',') s += c; while (cin >> c, c != ',') s1
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; string str; int main() { while (cin >> str, str != ".") { int len = str.size(); for (int n = len; n; n-
阅读全文
摘要:点击查看代码 #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> using namespace std; string str; int n; int main() { cin >> n; while (n --) { cin >> str; int cnt = 0; char c; for (int i =
阅读全文
摘要:点击查看代码 #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
阅读全文
摘要:点击查看代码 #include<bits/stdc++.h> using namespace std; int data1, data2, ans = 0, sum; int d[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; i
阅读全文
摘要:点击查看代码 #include<bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int m, n, ans = 0; int lists[500]; int steps[25]; int machine[25][N]; int
阅读全文
摘要:点击查看代码 #include<bits/stdc++.h> using namespace std; long long n, m, total, sum1, sum2; int main() { cin >> n >> m; int min_mn = min(m ,n); for (int i
阅读全文