baobao has a sequence a
1,a
2,...,a
n. he would like to find a subset
sof
such that ∀i
,j∈s
, ai
⊕a
ja
i,
aj
)and ∣s
∣is maximum, where
⊕means bitwise exclusive or.
there are multiple test cases. the first line of input contains an integer
t, indicating the number of test cases. for each test case:
the first line contains an integer n(
1≤n≤105
), indicating the length of the sequence.
the second line contains n integers: a
1,a
2,...,a
n(
1≤ai
≤109
), indicating the sequence.
it is guaranteed that the sum of
nin all cases does not exceed 10
5.
for each test case, output an integer denoting the maximum size of s.
3 3
1 2 3 3
1 1 1 5
1 2323 534 534 5
2 3
2給出乙個序列a1,a2,a3.....,s中放的是子串行的下標,則在此子串行中存在i,j屬於s,使得 ai異或aj小於min(ai,aj)並且s的長度最大。
因為兩個數異或(相同為0,不同為1)時,若兩個數的二進位制表示的長度相同,則它們異或後得到的數將會比這兩個數都小,才會滿足題目條件,而當兩個數的二進位制表示的長度不同時,異或得到的數將會比這兩個數都大,不符合條件。所以本題就可以轉化為求這個序列中最多有幾個數的二進位制位數相同,這個最多的數即是最大的序列長度。
#include#include#include#includeusing namespace std;
int a[100001],b[100001];
mapm;
int main()
b[i]=count;
m[b[i]]++; //將有相同位數的數的個數儲存在map中
}
map::iterator i;
int mmax=-1;
for(i=m.begin();i!=m.end();i++)
printf("%d\n",mmax);
} return 0;
}
二進位制 二進位制起源
現代通訊技術的基礎是二進位制編碼。早在1865年麥克斯韋總結出麥克斯韋方程組之前,美國人摩斯 morse 於1837年發明了摩斯電碼和有線電報。有線電報的出現,具有劃時代的意義 它讓人類獲得了一種全新的資訊傳遞方式,這種方式 看不見 摸不著 聽不到 完全不同於以往的信件 旗語 號角 烽火,這也是二進...
判斷二進位製半整數(二進位制)
10年後,tokitsukaze大佬已經變成了年收入超百萬的的精英程式設計師,家裡沒錢也沒礦的teitoku,找tokitsukaze大佬借1000塊錢,然後tokitsukaze大佬說,借你1024吧,湊個整數。沒錯在2進製下1024是 二進位制整數 乙個正整數滿足其值為2的k次方 k為正整數 我...
mysql二進位制 MySql二進位制連線方式詳解
使用mysql二進位制方式連線 您可以使用mysql二進位制方式進入到mysql命令提示符下來連線mysql資料庫。例項以下是從命令列中連線mysql伺服器的簡單例項 root host mysql u root p enter password 在登入成功後會出現 mysql 命令提示視窗,你可以...