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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Vasya has the sequence consisting of?n?integers. Vasya consider the pair of integers?x?and?y?k-interesting, if their binary representation differs from each other exactly in?k?bits. For example, if?k?=?2, the pair of integers?x?=?5?and?y?=?3?is?k-interesting, because their binary representation?x=101?and?y=011?differs exactly in two bits.

Vasya wants to know how many pairs of indexes (i,?j) are in his sequence so that?i?<?j?and the pair of integers?ai?and?aj?is?k-interesting. Your task is to help Vasya and determine this number.

Input

The first line contains two integers?n?and?k?(2?≤?n?≤?105,?0?≤?k?≤?14) — the number of integers in Vasya's sequence and the number of bits in which integers in?k-interesting?pair should differ.

The second line contains the sequence?a1,?a2,?...,?an?(0?≤?ai?≤?104), which Vasya has.

Output

Print the number of pairs (i,?j) so that?i?<?j?and the pair of integers?ai?and?aj?is?k-interesting.

Examples

Input

4 1 0 3 2 1

Output

4

Input

6 0 200 100 100 100 200 200

Output

6

Note

In the first test there are 4?k-interesting?pairs:

  • (1,?3),
  • (1,?4),
  • (2,?3),
  • (2,?4).

In the second test?k?=?0. Consequently, integers in any?k-interesting?pair should be equal to themselves. Thus, for the second test there are 6?k-interesting?pairs:

  • (1,?5),
  • (1,?6),
  • (2,?3),
  • (2,?4),
  • (3,?4),
  • (5,?6).

題目大意:

給你N個數的一個序列a,如果有兩個數二進制中有K個位置不同,那么對應就算作一對可行解,問一共有多少對可行解。

(2?≤?n?≤?1e5,?0?≤?k?≤?14,?0?≤?ai?≤?1e4)

解題報告:

? 介紹這個題的兩種寫法。首先很顯然看x和y有多少個位子不同,直接看x^y對應的二進制中1的個數即可。

所以第一種想法啊十分好想,預處理1~20000所有數字的1的個數,然后暴力枚舉1e4以內的每個數字i和j,如果i^1的1的個數等于k,則直接統計i,j兩個數的出現次數。我這里偷懶了沒預處理,直接用內置函數了。這種方法復雜度O(1e8)

第二種方法就是讀入完k之后,先暴力枚舉所有1的個數等于k的數,打表可以發現對任意一個k,1e4以內不會超過3000個數。問題等價于求x^y=z,x和y符合的二元組個數,已知x<=1e4,z最多3000個,所以直接枚舉x和z來反求y。復雜度O(3e8)左右。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 1<<15; int n,k; int dp[MAX]; vector<int> vv; int cnt[MAX],mx; ll ans; int main() { // cout << (1<<14) << endl;cin >> n >> k;for(int x,i = 1; i<=n; i++) {scanf("%d",&x); dp[x]++; mx = max(mx,x);}if(k == 0) {for(int i = 0; i<=mx; i++) ans += 1LL*dp[i]*(dp[i]-1)/2;cout << ans << endl; return 0;}for(int i = 0; i<=mx; i++) {for(int j = i+1; j<=mx; j++) {if(__builtin_popcount(i^j) == k) {ans += 1LL*dp[i] * dp[j];}}} cout << ans << endl;return 0 ; }

?

總結

以上是生活随笔為你收集整理的【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 91毛片在线观看 | 国产91丝袜在线播放九色 | 一区二区三区免费高清视频 | 性欢交69精品久久久 | 久久免费视频6 | 日本中文不卡 | 国产精品ww | 色婷婷久久综合中文久久蜜桃av | 中文字幕无码精品亚洲资源网久久 | 制服丝袜成人动漫 | 亚洲爱爱图 | 久久草国产 | 好男人www日本 | 国产剧情一区在线 | 亚洲www在线 | 99看片 | 国产大学生视频 | 国产精品久久毛片 | 欧美人成在线视频 | 国产aⅴ无码片毛片一级一区2 | 亚洲成人生活片 | 久久精品视频2 | 免费看日批视频 | 一级片美女 | 欧美日韩高清在线播放 | 日本激情久久 | 最近免费中文字幕大全免费版视频 | 88福利视频 | 亚洲第一网址 | 国产aaa视频 | 精品日韩一区 | 超级碰在线观看 | 精品久久久久久久 | 黄色免费一级片 | 亚洲国产精品无码久久 | 久久无码国产视频 | 激情五月婷婷在线 | 国产精品无码免费专区午夜 | 国产com| 国产女同91疯狂高潮互磨 | 日批视频 | 国产一区二区三区观看 | 婷婷丁香激情 | 加勒比综合在线 | 亚洲AV综合色区国产精品天天 | 成人性生活免费视频 | 神马伦理视频 | 免费人成在线观看网站 | 国产女厕一区二区三区在线视 | 在线观看wwww | 亚洲伊人久久久 | 93久久精品日日躁夜夜躁欧美 | 色视频在线播放 | 少妇床戏av | 成人午夜淫片100集 伊人久久国产 | 男女黄色又爽大片 | 日韩中文字幕视频在线 | 亚洲国产精品一区 | 无限国产资源 | 少妇一级片| 精品无码久久久久久久久成人 | 性五月天 | 日本婷婷 | 四虎一国产精品一区二区影院 | 亚洲精品免费播放 | 欧美日韩国产电影 | 在线免费观看a视频 | 国产精品综合在线 | 亚洲熟女少妇一区 | 日本欧美色图 | 美女一级黄 | 夜夜爽天天干 | 亚洲影院av | 欧美一级视频免费 | 国产激情网站 | 性生交大全免费看 | 亚洲激情av| 久热在线视频 | 美女扒开屁股让男人桶 | 清纯唯美亚洲 | 亚洲视频在线免费看 | 91丨porny丨中文 | av老司机在线观看 | 日本少妇高潮喷水xxxxxxx | 少妇又色又紧又爽又刺激视频 | 男女爽爽视频 | 大桥未久视频在线观看 | 四虎精品在线播放 | 色图社区 | 国产精品乱码妇女bbbb | 黄色大片免费观看视频 | 精品人人妻人人澡人人爽牛牛 | 精品国产露脸精彩对白 | 国产精品黄色大片 | 国产人成一区二区三区影院 | 黄色片网站国产 | 精品无码av一区二区三区不卡 | 日本精品视频网站 | 91播放在线 |