码迷,mamicode.com
首页 > 其他好文 > 详细

Team Formation

时间:2017-05-08 00:19:10      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:using   isp   const   alt   upper   class   c++   blog   表示   

技术分享
 1 #include<bits/stdc++.h>
 2 
 3 const int Maxn = 1000005;
 4 
 5 #define ll long long
 6 using namespace std;
 7 int x[Maxn], pos[33];
 8 int main() {
 9     int T, N;
10     cin >> T;
11     while (T--) {
12         scanf("%d", &N);
13         for (int i = 0; i < N; i++) scanf("%d", &x[i]);
14         sort(x, x + N);
15 
16         long long ans = 0;
17         for (int i = 1; i < N; i++) {
18             memset(pos, 0, sizeof(pos));
19 
20             int k = x[i], cnt = 0, p = 0; //  cnt -> x[i]二进制中0的个数,p表示0的位置
21             while (k) {
22                 if ((k & 1) == 0) pos[cnt++] = p;
23                 k >>= 1;
24                 p++;
25             }
26 
27             for (int j = 0; j < cnt; j++) {
28                 int a = 1 << pos[j], b = (1 << (pos[j] + 1)) - 1;
29                 ans += upper_bound(x, x + i, b) - lower_bound(x, x + i, a);
30             }
31         }
32         printf("%lld\n", ans);
33     }
34 }
View Code

 

Team Formation

标签:using   isp   const   alt   upper   class   c++   blog   表示   

原文地址:http://www.cnblogs.com/NWUACM/p/6822867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!