zoukankan      html  css  js  c++  java
  • zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494

    The 12th Zhejiang Provincial Collegiate Programming Contest - B
    Team Formation

    Time Limit: 3 Seconds      Memory Limit: 131072 KB

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university.

    Edward knows the skill level of each student. He has found that if two students with skill level A and B form a team, the skill level of the team will be A ⊕ B, where ⊕ means bitwise exclusive or. A team will play well if and only if the skill level of the team is greater than the skill level of each team member (i.e. A ⊕ B > max{AB}).

    Edward wants to form a team that will play well in the contest. Please tell him the possible number of such teams. Two teams are considered different if there is at least one different team member.

    Input

    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 (2 <= N <= 100000), which indicates the number of student. The next line contains N positive integers separated by spaces. The ith integer denotes the skill level of ith student. Every integer will not exceed 109.

    Output

    For each case, print the answer in one line.

    Sample Input

    2
    3
    1 2 3
    5
    1 2 3 4 5
    

    Sample Output

    1
    6
    

    分析:

    任选两个数,异或大于他们两个数

    思路:对于一个数字的二进制形式,我们与比它小的比较,如果对应位互异,那么肯定是可行的

    AC代码:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <set>
     8 #include <vector>
     9 #include <math.h>
    10 #include <algorithm>
    11 using namespace std;
    12 #define ls 2*i
    13 #define rs 2*i+1
    14 #define up(i,x,y) for(i=x;i<=y;i++)
    15 #define down(i,x,y) for(i=x;i>=y;i--)
    16 #define mem(a,x) memset(a,x,sizeof(a))
    17 #define w(a) while(a)
    18 #define LL long long
    19 const double pi = acos(-1.0);
    20 #define Len 20005
    21 #define mod 19999997
    22 const int INF = 0x3f3f3f3f;
    23 
    24 int t,n,a[100005],bit[100];
    25 
    26 int main()
    27 {
    28     int i,j,k;
    29     scanf("%d",&t);
    30     w(t--)
    31     {
    32         mem(bit,0);
    33         scanf("%d",&n);
    34         up(i,0,n-1)
    35         {
    36             scanf("%d",&a[i]);
    37             for(j = 31;j>=0;j--)
    38             {
    39                 if(a[i]&(1<<j))
    40                 {
    41                     bit[j]++;
    42                     break;
    43                 }
    44             }
    45         }
    46         LL ans = 0;
    47         up(i,0,n-1)
    48         {
    49             if(a[i])
    50             {
    51                 int l = 31;
    52                 w(1)
    53                 {
    54                     if(a[i]&(1<<l)) break;
    55                     l--;
    56                 }
    57                 w(l>=0)
    58                 {
    59                     if(!(a[i]&(1<<l))) ans+=bit[l];
    60                     l--;
    61                 }
    62             }
    63         }
    64         printf("%lld
    ",ans);
    65     }
    66 
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    免费下载!8套最新出炉的扁平化设计风格图标
    modern.IE – Web 开发必备的 IE 浏览器测试工具
    优秀案例!教您如何设计现代简约风格网页
    Mondrian – 开源的矢量图形 Web 应用程序
    超精美!10款专业的高质量名片设计模板
    英文字体下载大全:35款高品质英文字体
    免费下载!Twitter Bootstrap V3 矢量界面素材
    WOW.js – 在页面滚动时展现动感的元素动画效果
    Cool!12幅由小图片组成的创意图像重组作品
    InstantClick – 快速响应!让你的网站与众不同
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4456728.html
Copyright © 2011-2022 走看看