原创 C++ 11 多線程學習筆記1 --線程創建

https://www.bilibili.com/video/av39161756?p=1 併發編程 包括多進程編程和多線程編程 進程之間相互通訊的方法 文件 管道 消息隊列 多線程的優點 線程啓動速度快 輕量級 開銷低 多

原创 leetcode 53. 最大子序和

class Solution { public: int maxSubArray(vector<int>& nums) { if(nums.size() == 1){ return

原创 C++ 11 多線程學習筆記3 -- 死鎖

https://www.bilibili.com/video/av39161756?p=4 1.擁有一些資源,同時請求一些資源 #include <iostream> #include <thread> #include <fut

原创 leetcode 105. 從前序與中序遍歷序列構造二叉樹

遞歸, 在中序中找前序的第一個元素, 之後切割成兩個相同子問題 class Solution { public: TreeNode* buildTree(vector<int>& preorder, vector<int>

原创 C++ 11 多線程學習筆記2 --數據競爭和互斥 LogFile

https://www.bilibili.com/video/av39161756?p=3 1.lock和unlock #include <iostream> #include <thread> #include <future>

原创 EOJ Monthly 2020.1 A. 迴文時間

https://acm.ecnu.edu.cn/contest/247/problem/A/ 因爲是對稱的,只考慮前七位 2020012 | 2100202 0123 45 6 2020 | 01 | 2 年 | 月

原创 假期作業目錄

(二選一) poj1636 Prison rearrangement(連通分量+揹包) poj1088 滑雪(帶有備忘的遞歸|拓撲排序) (二選一) poj2366 poj3233 (二選一) poj1753 Flip Game

原创 leetcode 382. 鏈表隨機節點

從頭開始計數 第i個點選擇的概率是1i\frac{1}{i}i1​ 只需要區[0,i-1]的隨機數,如果,取到了0,就更新返回值,否則不更新 class Solution { public: /** @param head

原创 leetcode 307. 區域和檢索 - 數組可修改 前綴和 | 線段樹

前綴和 查詢是O(1) 更新是O(n) class NumArray { public: vector<int> sum; vector<int> nums; NumArray(vector<int>& n

原创 leetcode 56. 合併區間

區間左端點進行排序 如果intervals小於等於一個元素直接返回 如果大於1個 按照左邊點進行排序 從左至右依次合併 class Solution { public: static bool cmp(vector<in

原创 POJ 2366 Sacrament of the sum 二分查找 哈希表

題幹那麼長,就是在兩個數組裏面分別找一個數,使得和爲10000 法一:二分查找 法二:數組(哈希) 轉載自 https://www.cnblogs.com/wwdf/p/5781351.html #include<cstdio>

原创 leetcode 303. 區域和檢索 - 數組不可變

前綴和 class NumArray { public: vector<int> sum; NumArray(vector<int>& nums) { if(nums.size()>0){

原创 leetcode 589. N叉樹的前序遍歷

遞歸 class Solution { public: vector<int> ret; vector<int> preorder(Node* root) { findw(root);

原创 DUTOJ-1018: totoday的難題

一共三種情況 白(-2) => 黑(+1)最終 白(-2)黑(+1) 白(-1)黑(-1) => 白(+1) 最終 黑(-1) 黑(-2) => 黑(+1) 最終 黑(-1) 可以看出白球只能是每次減少2 最後剩餘一個球,那麼白

原创 leetcode 496. 下一個更大元素 I

用map記錄nums2裏面每一個元素的下標 然後遍歷nums1 從下標位置的下一個元素開始找 class Solution { public: vector<int> nextGreaterElement(vector<i