浙江省第十二届省赛 B - Team Formation
Description
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{A, B}).
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
题意:
输入n个数:任意两个数进行异或,问异或值大于这两个数的最大值的情况共有几种
题解:
首先将每个数的最高位哈希,然后遍历每个数。每个数转化为二进制数,二进制中只要当前位为0,那么异或此位为最高位的数一定比这两个数大。
代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <string>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
    cin.tie();\
    cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
+;
int arr[N];
];
int main()
{
    IO
    int T;
    cin>>T;
    while(T--){
        memset(ans,,sizeof(ans));
        ;
        cin>>n;
        For(i,,n)
        {
            cin>>arr[i];
            ans[(int )log2(arr[i])]++;
        }
        For(i,,n){
            ]={};
            int x = arr[i];
            while(x)
            {
                int x1 = x;
                x&=x-;
                bit[(;
            }
            For(j,,()
                if(!bit[j])
                    res +=ans[j];
        }
        cout<<res<<endl;
    }
    ;
}
浙江省第十二届省赛 B - Team Formation的更多相关文章
- 浙江省第十二届省赛 Beauty of Array(思维题)
		
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
 - 湖南省第十二届省赛:Parenthesis
		
Description Bobo has a balanced parenthesis sequence P=p1 p2…pn of length n and q questions. The i-t ...
 - 2015 浙江省赛B  Team Formation (技巧,动归)
		
Team Formation For an upcoming programming contest, Edward, the headmaster of Marjar University, is ...
 - HZNU第十二届校赛赛后补题
		
愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...
 - 第十二届湖南省赛G - Parenthesis (树状数组维护)
		
Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of length n and q questions. The i-th questio ...
 - 第十二届湖南省赛 (B - 有向无环图 )(拓扑排序+思维)好题
		
Bobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始.点 v 结束的路径). 为了方便,点用 1,2,…,n 编号. 设 count(x,y) 表示点 x 到点 y ...
 - 第十二届湖南省赛 A - 2016 ( 数学,同余转换)
		
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 ...
 - Little Sub and Traveling(杭师大第十二届校赛E题)   欧拉回路
		
题目传送门 题目大意: 从0出发,每次只能跳到(i*2)%n或者(i*2+1)%n,求字典序最大的哈密顿回路. 思路: 首先n为奇数时无解,先来证明这一点. 先假设n为奇数,若要回到原点,则必定有一步 ...
 - Little Sub and Piggybank  (杭师大第十二届校赛G题)    DP
		
题目传送门 题意:每天能往存钱罐加任意实数的钱,每天不能多于起那一天放的钱数.如果某一天的钱数恰好等于那天的特价商品,则可以买,求最后的最大快乐值. 思路:先来一段来自出题人的题解: 显然的贪心:如果 ...
 
随机推荐
- DES(Data Encryption Standard)数据加密标准
			
DES算法入口参数 DES算法的入口参数有三个:Key.Data.Mode.其中Key为7个字节共56位,是DES算法的工作密钥.Data为8个字节64位,是要被加密或解密的数据;Mode为DES的工 ...
 - 【Python】python之Character string
			
1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. ...
 - C#范型实例化对象
			
T s = System.Activator.CreateInstance<T>();
 - 2018牛客多校第一场 B.Symmetric Matrix
			
题意: 构造一个n*n的矩阵,使得Ai,i = 0,Ai,j = Aj,i,Ai,1+Ai,2+...+Ai,n = 2.求种类数. 题解: 把构造的矩阵当成邻接矩阵考虑. 那么所有点的度数都为2,且 ...
 - [USACO07DEC]美食的食草动物Gourmet Grazers
			
---题面--- 题解: 首先观察题面,直觉上对于一头奶牛,肯定要给它配pi和qi符合条件的草中两者尽量低的草,以节省下好草给高要求的牛. 实际上这是对的,但观察到两者尽量低这个条件并不明确,无法用于 ...
 - THUSC2014酱油记
			
Day0: 坐飞机到北京,然后报到...跟jason_yu分到一个房间,刚好可以蹭点RP.发现房间460RMB/晚,但再带一份早餐就500RMB,难道早餐是40RMB么...在一家川菜馆吃的午晚餐,感 ...
 - 停课day5
			
一转眼,已经停课五天了. 高二大佬们已经都走了,在机房里面呆着,有时感觉很孤寂. 但是为了能学好竞赛,这些都是在所不惜的. 好像多打打比赛啊,可是cf要FQ,洛谷之类的比赛还不勤. 哎,先去学一发SP ...
 - [HEOI2017]分手是祝愿 期望概率dp 差分
			
经分析可知:I.操作每个灯可看做一种异或状态 II.每个状态可看做是一些异或状态的异或和,而且每个异或状态只能由它本身释放或放入 III.每一种异或状态只有存在不存在两中可行状态,因此这些灯只有同时处 ...
 - UVA10480:Sabotage(最小割+输出)
			
Sabotage 题目链接:https://vjudge.net/problem/UVA-10480 Description: The regime of a small but wealthy di ...
 - Endnote 中文参考文献样式修改版
			
http://blog.yuelong.info/post/endnote-gbt7714-2005.html 很多人不知道 EndNote 是自带中文参考文献引用样式的,即符合<文后参考文献著 ...