当前位置:网站首页>2166. Design bit set
2166. Design bit set
2022-07-03 20:02:00 【_ Cauchy】
subject
BitSet Bitset It is a data structure that can store bits in a compact form .
Please realize Bitset class .Bitset(int size) use size Bit initialization Bitset , All the seats are 0 .
void fix(int idx) Mark the subscript as idx The value on the bit of is updated to 1 . If the value is already 1 , Nothing will change .
void unfix(int idx) Mark the subscript as idx The value on the bit of is updated to 0 . If the value is already 0 , Nothing will change .
void flip() Flip Bitset The value on each bit in . let me put it another way , All values are 0 The bit will become 1 , vice versa .
boolean all() Check Bitset in every Whether the values of are all 1 . If this condition is met , return true ; otherwise , return false .
boolean one() Check Bitset in whether At least one The value of is 1 . If this condition is met , return true ; otherwise , return false .
int count() return Bitset The median is 1 A bit of total .
String toString() return Bitset The current composition of . Be careful , In the result string , The first i Characters at subscripts should be the same as Bitset No i It's the same .
Code
class Bitset {
public:
int n; // Total length
int sum; // 1 The number of
bool fp; // reverse
vector<bool> st;
Bitset(int size) {
st.resize(size);
n = size;
fp = false;
sum = 0;
}
void fix(int idx) {
// idx Set up 1
// fp==false: st[idx]==false, sum++
// fp==true: st[idx]==true, sum++
if(!(st[idx] ^ fp)) sum++, st[idx] = !st[idx];
}
void unfix(int idx) {
// idx Set up 0
if(st[idx] ^ fp) sum--, st[idx] = !st[idx];
}
void flip() {
fp = !fp;
sum = n - sum;
}
bool all() {
return sum == n;
}
bool one() {
return sum >= 1;
}
int count() {
return sum;
}
string toString() {
string res = "";
for (int i = 0; i < n; i++)
if(st[i] ^ fp) res += '1';
else res += '0';
return res;
}
};
边栏推荐
- Initialization and instantiation
- Popularize the basics of IP routing
- Professional interpretation | how to become an SQL developer
- unittest框架基本使用
- 44. Concurrent programming theory
- Pat grade B 1009 is ironic (20 points)
- February 14-20, 2022 (osgear source code debugging +ue4 video +ogremain source code transcription)
- 6. Data agent object Defineproperty method
- Xctf attack and defense world crypto advanced area best_ rsa
- Derivation of decision tree theory
猜你喜欢
![[effective Objective-C] - block and grand central distribution](/img/09/22b979b97ea13d649b4b904637b79f.jpg)
[effective Objective-C] - block and grand central distribution

Teach you how to quickly recover data by deleting recycle bin files by mistake

PR 2021 quick start tutorial, how to create a new sequence and set parameters?
![2022-06-30 advanced network engineering (XIV) routing strategy - matching tools [ACL, IP prefix list], policy tools [filter policy]](/img/b6/5d6b946d8001e2d73c2cadbdce72fc.png)
2022-06-30 advanced network engineering (XIV) routing strategy - matching tools [ACL, IP prefix list], policy tools [filter policy]

Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate

How to improve data security by renting servers in Hong Kong

2.4 conversion of different data types

PR FAQ: how to set PR vertical screen sequence?
![Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue](/img/5b/fc776a1982e24b82984d82be6a016f.jpg)
Meso tetra [P - (p-n-carbazole benzylidene imino)] phenylporphyrin (tcipp) /eu (tcipp) [pc( α- 2-oc8h17) 4] and euh (tcipp) [pc (a-2-oc8h17) 4] supplied by Qiyue

AcWing 1460. Where am i?
随机推荐
Micro service knowledge sorting - asynchronous communication technology
2022-06-25 网工进阶(十一)IS-IS-三大表(邻居表、路由表、链路状态数据库表)、LSP、CSNP、PSNP、LSP的同步过程
Difference between surface go1 and surface GO2 (non professional comparison)
PR notes:
BOC protected alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC / alanine zinc porphyrin Zn · TAPP ala BOC supplied by Qiyu
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
IPv6 experiment
Day10 ---- 强制登录, token刷新与jwt禁用
FPGA learning notes: vivado 2019.1 project creation
Make a simple text logo with DW
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
Blue Bridge Cup: the fourth preliminary - "simulated intelligent irrigation system"
Leetcode daily question solution: 540 A single element in an ordered array
Part 28 supplement (XXVIII) busyindicator (waiting for elements)
Chapter 1: extend the same code decimal sum s (D, n)
PR 2021 quick start tutorial, material import and management
FAQs for datawhale learning!
HCIA-USG Security Policy
4. Data splitting of Flink real-time project
Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!