update
This commit is contained in:
parent
48b958c476
commit
ab63237116
52
20240906/bitset.cpp
Normal file
52
20240906/bitset.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <array>
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
typedef unsigned int u8;
|
||||
typedef int i8;
|
||||
|
||||
const u8 MAX = 1e5+1;
|
||||
|
||||
constexpr std::array<u8, (size_t)MAX> initLog2(){
|
||||
std::array<u8, (size_t)MAX> 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<u8, (size_t)MAX> 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<u8> get1Dir()const{
|
||||
std::vector<u8> 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<<std::format("{0}.getLowbit()={1}\n{0}.get1Dir()={2}",b.data,b.getLowbit(),b.getLowbit());
|
||||
}
|
10
test.cpp
Normal file
10
test.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
unsigned int a{};
|
||||
for(;;){a++;}
|
||||
cout<<a<<endl;
|
||||
}
|
10
xmake.lua
10
xmake.lua
@ -5,8 +5,10 @@ if is_mode("debug") then
|
||||
end
|
||||
if is_mode("release") then
|
||||
add_cxxflags("-march=native")
|
||||
add_cxxflags("-fconstexpr-loop-limit=2147483647")
|
||||
add_cxxflags("-fconstexpr-ops-limit=2147483647")
|
||||
end
|
||||
set_languages("c++17")
|
||||
set_languages("c++23")
|
||||
set_warnings("all")
|
||||
|
||||
target("P1158")
|
||||
@ -39,3 +41,9 @@ target("P2661")
|
||||
|
||||
target("6261")
|
||||
add_files("20240901/6261/6261.cpp")
|
||||
|
||||
target("test")
|
||||
add_files("test.cpp")
|
||||
|
||||
target("bitset")
|
||||
add_files("20240906/bitset.cpp")
|
Loading…
Reference in New Issue
Block a user