日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

bitset中_Find_first()与_Find_next()函数

發布時間:2024/10/12 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bitset中_Find_first()与_Find_next()函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

bitset中_Find_first()與_Find_next()函數

很有趣但是沒怎么有用的兩個函數。

_Find_fisrt就是找到從低位到高位第一個1的位置

#include<bits/stdc++.h> int main() {std::bitset<1001> B;B.set(2); B.set(4); B.set(233);std::cout << B._Find_first(); }

輸出結果為2

_Find_next就是找到當前位置的下一個1的位置

#include<bits/stdc++.h> int main() {std::bitset<1001> B;B.set(2); B.set(4); B.set(233);std::cout << B._Find_next(5); }

輸出結果為233 1001,也就是說如果某個元素之后沒有元素的話會返回bitset的大小

那么我們可以這樣去遍歷一個bitset

#include<bits/stdc++.h> int main() {std::bitset<1001> B;B.set(2); B.set(4); B.set(233);for(int i = B._Find_first(); i != B.size(); i = B._Find_next(i)) std::cout << i << ' '; }

輸出結果為2 4 233。

按照糖教主的說法,這樣遍歷的復雜度是\(O(\frac{n}{w})\)的。\(n\)是bitset的大小,\(w\)與計算機有關,一般為\(32\)\(64\)。也就是說遍歷bitset的復雜度與bitset內1的個數無關

同時Swistakk大佬說

I don't remember it in details, but bitset in fact has a function for k-th bit, however it is declared as private... I have no idea why would someone not expose such useful function to world and deem it as private, but #define private public is there to help you

但是我翻了半天bitset的源代碼也沒找到與第K有關的函數qwq。如果有知道的大佬歡迎在評論區留言,本蒟蒻感激不盡

參考資料

bitset Find_first and Find_next

轉載于:https://www.cnblogs.com/zwfymqz/p/10565487.html

總結

以上是生活随笔為你收集整理的bitset中_Find_first()与_Find_next()函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。