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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

子网掩码+ip地址_C ++程序使用位掩码查找唯一编号

發(fā)布時間:2025/3/11 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 子网掩码+ip地址_C ++程序使用位掩码查找唯一编号 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

子網(wǎng)掩碼+ip地址

Problem statement: C++ Program to find unique number in an array of n numbers in which except one (unique number) rest all are present thrice.

問題陳述: C ++程序在n個數(shù)字的數(shù)組中查找唯一數(shù)字,其中除一個(唯一數(shù)字)外其余所有其余三次。

Constraints: n<10^5

約束: n <10 ^ 5

Example:

例:

Input:101 2 3 2 4 1 2 3 1 3Output:4

Solution: Except 4 rest all have multiplicity of 3 in array. For instance 4 are represented as 100 in binary .Starting from left most bit is the first index of count array.

解決方案:除了4個其余的所有數(shù)組都具有3的多重性。 例如,4用二進制表示為100.從最左邊的位開始是count數(shù)組的第一個索引。

Problem explanation:

問題說明:

  • Make a count array (initialize all elements to 0) to store the bits of each number in input array.

    創(chuàng)建一個計數(shù)數(shù)組(將所有元素初始化為0),以將每個數(shù)字的位存儲在輸入數(shù)組中。

  • In each iteration access the input number and extract its bits to store in count array for instance if number is 6 which is 110 in binary, so 110 & 1 stores 0 at count[0], then right shift the number to obtain the next bit from left that is 11 & 1 stores 1 at count[1] and similarly again >> number to get 1 again at count[2].

    在每次迭代中,訪問輸入數(shù)字并提取其比特以存儲在計數(shù)數(shù)組中,例如,如果數(shù)字為6(二進制數(shù)為110),則110&1在count [0]處存儲0,然后右移數(shù)字以獲得下一個比特從11&1的左起在count [1]處存儲1,同樣>> >>在count [2]處再次獲得1。

  • After each iteration count array is updated. Now since every element except one occurs thrice in input array, therefore bits at every index exist in the form of 3n and 3n +1.

    每次迭代后,更新計數(shù)數(shù)組。 現(xiàn)在,由于除一個元素外的每個元素都在輸入數(shù)組中出現(xiàn)三次,因此每個索引處的位都以3n和3n +1的形式存在。

  • So taking modulus by 3 leaves only unique number's bits in count array as remainders. This will give the binary number of the unique number.

    因此,將模數(shù)減3只會在計數(shù)數(shù)組中保留唯一數(shù)字的位數(shù)作為余數(shù)。 這將給出唯一編號的二進制編號。

  • Now convert binary to decimal by ∑ multiply (bit with 2^index at respective index).

    現(xiàn)在,將∑乘以將二進制轉換為十進制(在相應的索引處具有2 ^ index的位)。

  • Return the unique number in array.

    返回數(shù)組中的唯一編號。

  • .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

    Program:

    程序:

    #include <iostream> using namespace std;int unique(int *arr,int n) { //array of size 64 for max 64 bit sizeint count[64]={0}; //count array stores bit of every numberfor(int k=0;k<n;k++) { int i=0;int num=arr[k]; while(num>0){// extract bit count[i]+=(num&1); i++;// right shift to get next leftmost bitnum=num>>1; }}// starting from first index 2^0=1 int power=1; int result=0;for(int j=0;j<64;j++){// take modulus of count array by 3count[j] %=3; result+=count[j]*power;// binary to decimal operationpower=power<<1; }// if there is no unique number 0 is returnedreturn result; }int main() { int arr[50];int n;cout<<"Enter lenght of the array: ";cin>>n;cout<<"Enter array elements..."<<endl;for(int c=0;c<n;c++){cin>>arr[c];}cout<<unique(arr,n)<<" is the unique number in array.";return 0; }

    Output

    輸出量

    Enter lenght of the array: 4 Enter array elements... 10 10 10 40 40 is the unique number in array.

    翻譯自: https://www.includehelp.com/cpp-programs/find-unique-number-using-bit-masking.aspx

    子網(wǎng)掩碼+ip地址

    總結

    以上是生活随笔為你收集整理的子网掩码+ip地址_C ++程序使用位掩码查找唯一编号的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 理论片高清免费理伦片 | 九色自拍 | 欧美肥妇bwbwbwbxx | 都市激情第一页 | 喷水了…太爽了高h | 一级黄色大片视频 | 国产又粗又猛又爽又黄的 | 七仙女欲春2一级裸体片 | 国产精品视频网 | 丝袜 亚洲 另类 国产 制服 | 潘金莲一级淫片免费放动漫 | 天天看黄色片 | 国产98在线| 亚洲精品九九 | 成人免费高清 | 国产午夜精品一区二区三区欧美 | 日韩欧美精品在线视频 | 日本精品一区二区三区在线观看 | 国产成人亚洲综合 | 成人欧美精品一区二区 | 成人在线中文字幕 | 亚洲精品国产欧美 | www.男女| 浪漫樱花动漫在线观看免费 | 亚洲一区在线视频观看 | 国产日韩欧美视频在线观看 | 色综合久久久无码中文字幕波多 | 精品久久久999 | 精品视频日韩 | 好吊视频一区 | 涩涩视频免费 | 久久一区视频 | 午夜草逼 | 美女毛片视频 | 中文字幕久久av | 香蕉视频一区二区 | 高清久久久久久 | 99精品在线看 | 亚洲另类欧美日韩 | 婷婷调教口舌奴ⅴk | 国产成人无码专区 | 国产无码精品在线播放 | 久久美女av | 国产欧美日韩综合精品一区二区三区 | 午夜影院在线观看视频 | 亚洲区在线 | 日韩一级视频在线观看 | 超碰免费在线播放 | 欧美一区二区三区免费视频 | 少妇高潮喷水在线观看 | 欧美一区二区区 | 丁香色婷婷 | 国产成人综合亚洲 | 中文字幕 国产 | 蜜臀av性久久久久蜜臀aⅴ麻豆 | 日本少妇一区二区三区 | 中文字幕www| 亚洲理论片在线观看 | 国产伦精品一区二区三区在线观看 | 亚洲综合中文 | 午夜影院免费观看 | 天天看片天天干 | 国产色av| 亚洲色图美腿丝袜 | 亚洲另类欧美日韩 | 尤物91| 国产精品白浆一区二小说 | 激情福利视频 | 婷婷影院在线观看 | 激情黄色小说网站 | 操碰视频在线 | 人人爽久久涩噜噜噜网站 | 日韩激情电影在线 | 特黄aaaaaaa片免费视频 | 天天操天天干天天 | 亚洲午夜不卡 | 日韩视频一二三 | 国产91色 | 2023毛片| 在线观看色网站 | 九九激情网 | 亚洲激情视频在线观看 | 天堂视频网 | 国产又黄又嫩又滑又白 | 免费久久一级欧美特大黄 | 自拍1区 | 黑人黄色录像 | 国产成人三级一区二区在线观看一 | 五月婷婷中文字幕 | 性高湖久久久久久久久免费 | 国产成人无码www免费视频播放 | 日韩视频成人 | 久久久久国 | 午夜福利123| 玖玖热在线视频 | 麻豆免费在线视频 | 国产精品久久久久久久久久久久久久久久久久 | 日韩欧美大片 | 亚洲婷婷一区 |