From ab632371162e8528b6b5a649396f66c280f5e601 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sat, 7 Sep 2024 00:06:31 +0800 Subject: [PATCH] update --- 20240906/bitset.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++ test.cpp | 10 +++++++++ xmake.lua | 12 +++++++++-- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 20240906/bitset.cpp create mode 100644 test.cpp diff --git a/20240906/bitset.cpp b/20240906/bitset.cpp new file mode 100644 index 0000000..fa319de --- /dev/null +++ b/20240906/bitset.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +typedef unsigned int u8; +typedef int i8; + +const u8 MAX = 1e5+1; + +constexpr std::array initLog2(){ + std::array log2{}; + log2[1]=0; + for(int i=2;i<=(int)MAX-1;i++){ + log2[i]=log2[i/2]+1; + } + return log2; +} + +class BitIntSet{ +private: + constexpr static const std::array log2=initLog2(); +public: + i8 data; + + explicit BitIntSet(i8 n):data{n}{ + // checkLog2IsInitalized(); + } + int getLowbit()const{ + return this->data&((~this->data)+1); + } + int getLowbit(u8 n)const{ + return n&((~n)+1); + } + std::vector get1Dir()const{ + std::vector ret; + int temp=this->data; + while(temp>0){ + ret.push_back(log2[this->getLowbit()]); + temp-=getLowbit(temp); + } + return ret; + } +}; + +int main(){ + BitIntSet b(10); + std::cout< +using namespace std; + + + +int main(){ + unsigned int a{}; + for(;;){a++;} + cout<