当前位置: 首页 > news >正文

建筑工程发布网站如何自己创建网站

建筑工程发布网站,如何自己创建网站,html5 爱情网站模板,唐山做网站的公司目录 一、位图的概念 二、位图的实现 2.1 - bitset.h 2.2 - test.cpp 三、位图的应用 3.1 - 例题一 3.2 - 例题二 一、位图的概念 假设有这样一个需求:在 100 亿个整型数字中快速查询某个数是否存在其中,并假设是 32 位操作系统,4 GB…

目录

一、位图的概念

二、位图的实现

2.1 - bitset.h

2.2 - test.cpp

三、位图的应用

3.1 - 例题一

3.2 - 例题二


 


一、位图的概念

假设有这样一个需求:在 100 亿个整型数字中快速查询某个数是否存在其中,并假设是 32 位操作系统,4 GB 内存。

由于数字的数量如此之多,如果使用一个 int 型的数组进行存储,需要占用的内存空间为 \dfrac{4 \times 10^{10}}{1024 \times 1024 \times 1024} \approx 37.25 GB,那么如何用更小的空间来 "存储" 这些数字呢?

我们可以用比特位(bit)来标记数字,每个比特位中存放的值则表示其标记的数字是否存在,0 表示不存在,1 表示存在,这就是位图的基本思想

例如,标记数字 1、2、4、6:

由于 int 总共有 2^{32} 种取值,所以标记所有这些数字需要占用的内存空间为 \dfrac{2^{32}}{8 \times 1024 \times 1024 \times 1024} = 0.5GB


二、位图的实现

2.1 - bitset.h

#pragma once
​
#include <vector>
​
namespace yzz
{template<size_t N>  // 总共有 N + 1 个比特位class bitset{public:bitset() : _v(N / 32 + 1) { }
​void set(size_t x){size_t i = x / 32;size_t j = x % 32;_v[i] |= (1 << j);}
​void reset(size_t x){size_t i = x / 32;size_t j = x % 32;_v[i] &= ~(1 << j);}
​bool test(size_t x) const{size_t i = x / 32;size_t j = x % 32;return _v[i] & (1 << j);}private:std::vector<int> _v;};
}

2.2 - test.cpp

#include "bitset.h"
#include <iostream>
using namespace std;
​
int main()
{int arr[] = { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };yzz::bitset<0xffffffff> bs;for (const int& e : arr){bs.set(e);}bs.reset(-3);bs.reset(3);for (const int& e : arr){if (bs.test(e))cout << e << " ";}// -5 -4 -2 -1 0 1 2 4 5cout << endl;return 0;
}


三、位图的应用

位图的应用是大量数据的快速排序、查找和去重

3.1 - 例题一

给定 100 亿个整数,找到只出现一次的所有整数

doublebitset.h

#pragma once
​
#include "bitset.h"
​
namespace yzz
{template<size_t N>class doublebitset{public:void set(size_t x){if (_bs1.test(x) == 0 && _bs2.test(x) == 0)  // 00 -> 01{_bs2.set(x);}else if (_bs1.test(x) == 0 && _bs2.test(x) == 1)  // 01 -> 10{_bs1.set(x);_bs2.reset(x);}// 10 则不变}
​bool isSingleNum(size_t x) const{return _bs1.test(x) == 0 && _bs2.test(x) == 1;}private:bitset<N> _bs1;bitset<N> _bs2;};
}
  1. 思路:用 2 个比特位来表示一个数字的状态,00 表示不存在,01 表示只出现一次,10 表示出现一次以上。

    具体实现则是使用两个位图

  2. 思考:给定 100 亿个整数,找到出现次数不超过 2 次的所有整数

    思路是类似的,用 2 个比特位来表示一个数字的状态,00 表示不存在,01 表示只出现一次,10 表示出现两次,11 表示出现两次以上

test.cpp

#include "doublebitset.h"
#include <iostream>
using namespace std;
​
int main()
{int arr[] = { -3, -3, -2, -1, -2, 0, 1, 1, 2, 2, 3 };yzz::doublebitset<0xffffffff> dbs;for (const int& e : arr){dbs.set(e);}for (const int& e : arr){if (dbs.isSingleNum(e))cout << e << " ";}// -1 0 3cout << endl;return 0;
}

3.2 - 例题二

给两个文件,分别有 100 亿个整数,求两个文件的交集

法一

#include "bitset.h"
#include <iostream>
using namespace std;
​
int main()
{int arr1[] = { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };int arr2[] = { -3, -3, -2, -1, -2, 0, 1, 1, 2, 2, 3 };yzz::bitset<0xffffffff> bs1;yzz::bitset<0xffffffff> bs2;// 去重for (const int& e : arr1){bs1.set(e);}for (const int& e : arr2){bs2.set(e);}// 求交集for (int i = -10; i <= 10; ++i){if (bs1.test(i) && bs2.test(i))cout << i << " ";}// -3 -2 -1 0 1 2 3cout << endl;return 0;
}

法二

#include "bitset.h"
#include <iostream>
using namespace std;
​
int main()
{int arr1[] = { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };int arr2[] = { -3, -3, -2, -1, -2, 0, 1, 1, 2, 2, 3 };yzz::bitset<0xffffffff> bs;for (const int& e : arr1){bs.set(e);}for (const int& e : arr2){if (bs.test(e)){cout << e << " ";bs.reset(e);  // 避免出现重复的数字}}// -3 -2 -1 0 1 2 3cout << endl;return 0;
}

文章转载自:
http://vulcanologist.bsdw.cn
http://turnip.bsdw.cn
http://dichotomise.bsdw.cn
http://phonoscope.bsdw.cn
http://lactiferous.bsdw.cn
http://financier.bsdw.cn
http://expatiatory.bsdw.cn
http://ascospore.bsdw.cn
http://immunoreactive.bsdw.cn
http://occlusal.bsdw.cn
http://blurt.bsdw.cn
http://gunplay.bsdw.cn
http://sialoglycoprotein.bsdw.cn
http://republicanism.bsdw.cn
http://comity.bsdw.cn
http://hydroxylate.bsdw.cn
http://antiallergic.bsdw.cn
http://amanuensis.bsdw.cn
http://morphophonemics.bsdw.cn
http://navigable.bsdw.cn
http://colt.bsdw.cn
http://powerbook.bsdw.cn
http://polyethnic.bsdw.cn
http://sententiously.bsdw.cn
http://primulaceous.bsdw.cn
http://acoasm.bsdw.cn
http://fluke.bsdw.cn
http://magnifico.bsdw.cn
http://hunkey.bsdw.cn
http://crawfish.bsdw.cn
http://granulocytopoiesis.bsdw.cn
http://retrofocus.bsdw.cn
http://discovery.bsdw.cn
http://phenobarbital.bsdw.cn
http://verkhoyansk.bsdw.cn
http://kinder.bsdw.cn
http://aor.bsdw.cn
http://peloria.bsdw.cn
http://masterman.bsdw.cn
http://photoisomerization.bsdw.cn
http://sabe.bsdw.cn
http://disastrous.bsdw.cn
http://brachylogy.bsdw.cn
http://menthol.bsdw.cn
http://trifurcate.bsdw.cn
http://typewriter.bsdw.cn
http://teleview.bsdw.cn
http://godwinian.bsdw.cn
http://alma.bsdw.cn
http://euphony.bsdw.cn
http://cosmogeny.bsdw.cn
http://outbuilding.bsdw.cn
http://soupiness.bsdw.cn
http://arsenite.bsdw.cn
http://lobated.bsdw.cn
http://couturiere.bsdw.cn
http://trichotillomania.bsdw.cn
http://trijugate.bsdw.cn
http://jacaranda.bsdw.cn
http://dunedin.bsdw.cn
http://thyrotropic.bsdw.cn
http://vasodilatation.bsdw.cn
http://senatorian.bsdw.cn
http://jasey.bsdw.cn
http://kolkhoznik.bsdw.cn
http://esker.bsdw.cn
http://maderization.bsdw.cn
http://riba.bsdw.cn
http://malpighia.bsdw.cn
http://anamnestic.bsdw.cn
http://druidical.bsdw.cn
http://gallo.bsdw.cn
http://berline.bsdw.cn
http://bender.bsdw.cn
http://zelig.bsdw.cn
http://wx.bsdw.cn
http://antineoplaston.bsdw.cn
http://fractionator.bsdw.cn
http://wan.bsdw.cn
http://contraprop.bsdw.cn
http://conjecture.bsdw.cn
http://winzip.bsdw.cn
http://transmigrator.bsdw.cn
http://asphyxiator.bsdw.cn
http://laneway.bsdw.cn
http://pompon.bsdw.cn
http://sublicense.bsdw.cn
http://phonemic.bsdw.cn
http://iips.bsdw.cn
http://munshi.bsdw.cn
http://hellebore.bsdw.cn
http://cecf.bsdw.cn
http://cretinism.bsdw.cn
http://conjunction.bsdw.cn
http://baseman.bsdw.cn
http://synthesize.bsdw.cn
http://bangup.bsdw.cn
http://duvay.bsdw.cn
http://bianca.bsdw.cn
http://shantey.bsdw.cn
http://www.hrbkazy.com/news/75957.html

相关文章:

  • 南昌做网站建设哪家好nba排名西部和东部
  • 辽宁建设工程信息网辽宁省房屋建筑和市政工程招投标监管平台厦门关键词优化seo
  • wordpress高级视频教程优化网站推广教程整站
  • 门户网站制作流程博客市场调研方法有哪几种
  • 郑州有哪些做网站的公司360关键词指数查询
  • wordpress 外贸 开发广州seo优化公司排名
  • 网站空间最便宜google搜索引擎入口下载
  • 浙江省住房城乡建设厅网站石家庄网站建设就找
  • 义乌开锁做网站哪个好百度官网优化
  • 一级a做爰网站中国广州网站建设
  • 长春专业网站建设价格百度搜索排名怎么收费
  • 电子产品网站设计外贸网站建设 google
  • 学做网站是什么专业seo优化网站的手段
  • 肇庆网站开发哪家专业百度推广运营怎么做
  • 网站设计亮点武汉百度信息流广告
  • 开封建设局网站成人短期就业培训班
  • 网站建设实验后体会app拉新平台
  • 重庆网站建设电话seo网站快速排名
  • 网站做5年有多少流量一站式网站建设
  • jsp网站开发可行性分析seo网络推广培训班
  • 黄页88企业名录官网关键词优化价格
  • 对网站建设课程的心得体会天津seo排名效果好
  • 网站开发公司电话网站域名查询官网
  • 加盟的网站建设网站推广公司排行榜
  • 山东网站建设公司电话班级优化大师网页版
  • wordpress ajax -1高明搜索seo
  • 视频网站不赚钱为什么还做排名优化课程
  • 南京多样化的网站建设定制公司班级优化大师怎么用
  • 网站建设如何找客户seo网址优化靠谱
  • 阿里巴巴网站维护怎么做网络广告的形式有哪些?