發表文章

目前顯示的是 1月, 2018的文章

shared pipe hlxSweExam

#include <cstdlib> #include <new> template <class T> struct Mallocator { typedef T value_type; Mallocator() = default; template <class U> constexpr Mallocator(const Mallocator<U>&) noexcept {} [[nodiscard]] T* allocate(std::size_t n) { if(n > std::size_t(-1) / sizeof(T)) throw std::bad_alloc(); if(auto p = static_cast<T*>(std::malloc(n*sizeof(T)))) return p; throw std::bad_alloc(); } void deallocate(T* p, std::size_t) noexcept { std::free(p); } }; template <class T, class U> bool operator==(const Mallocator<T>&, const Mallocator<U>&) { return true; } template <class T, class U> bool operator!=(const Mallocator<T>&, const Mallocator<U>&) { return false; } https://elloop.github.io/c++/2016-09-19/stl-apply-imp-95-simple-allocator http://www.cnblogs.com/suzhou/p/5381738.html http://www.justskins.com/forums/shm_open-vs-open-253314.html http://www.drdobbs.com/creati...

https://leetcode.com/contest/weekly-contest-68/problems/toeplitz-matrix/

class Solution { public: string reorganizeString(string S) { map<char, int> m; map<char, int>::iterator it; string ans; for (int i = 0; i < S.length(); i++) { it = m.find(S.at(i)); if (it != m.end()) { it->second++; } else { m.insert(make_pair(S.at(i), 1)); } } int max; vector<pair<int, char>> tmp; for (it = m.begin(); it != m.end(); it++) { tmp.push_back(make_pair(it->second, it->first)); } sort(tmp.begin(), tmp.end()); int sum = 0; for (int i = 0; i < tmp.size() - 1; i++) { sum += tmp[i].first; } if (tmp[(tmp.size()-1)].first > sum + 1) { return ans; } for (int i = 0; i < tmp.size(); i++) { int pos = 0; char c = tmp[i].second; int count = tmp[i].first; ...

https://leetcode.com/contest/weekly-contest-68/problems/reorganize-string/

class Solution { public: string reorganizeString(string S) { map<char, int> m; map<char, int>::iterator it; string ans; for (int i = 0; i < S.length(); i++) { it = m.find(S.at(i)); if (it != m.end()) { it->second++; } else { m.insert(make_pair(S.at(i), 1)); } } int max; vector<pair<int, char>> tmp; for (it = m.begin(); it != m.end(); it++) { tmp.push_back(make_pair(it->second, it->first)); } sort(tmp.begin(), tmp.end()); int sum = 0; for (int i = 0; i < tmp.size() - 1; i++) { sum += tmp[i].first; } if (tmp[(tmp.size()-1)].first > sum + 1) { return ans; } for (int i = 0; i < tmp.size(); i++) { int pos = 0; char c = tmp[i].second; int count = tmp[i].first; ...

https://leetcode.com/contest/weekly-contest-68/problems/max-chunks-to-make-sorted-ver-1/

class Solution { public: int maxChunksToSorted(vector<int>& arr) { vector<int> sorted(arr); sort(sorted.begin(), sorted.end()); vector<int> max; int max_now = -1; for (int i = 0; i < arr.size(); i++) { if (arr[i] > max_now) { max_now = arr[i]; max.push_back(arr[i]); } else max.push_back(max_now); } int total = 0; for (int i = 0; i < arr.size(); i++) { if (sorted[i] == max[i]) { total++; } } return total; } };