题目传送门

 /*
题意:找出符合 A^B > max (A, B) 的组数;
位运算:异或的性质,1^1=0, 1^0=1, 0^1=1, 0^0=0;与的性质:1^1=1, 1^0=0, 0^1=0, 0^0=0;
假设A < B,一定要满足B的最高位对应A的值是0,这样才可能>B(即0^1=1);
然后比赛时假设A的极限是类似0111111的情况,最后假设有误;
题解是先把每个数最高位(1)的位置统计个数,1<<4 的意思是 000010000;
只要与为0,表示最高位p位置的所有数字和当前a[i]异或一定满足,累加ans; 位运算不熟悉, '⊕'还是别人告诉我是异或的;
详细解释:http://blog.csdn.net/LYHVOYAGE/article/details/45285731
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int bit[]; void solve(int x)
{
int p = ;
while (p >= )
{
if (x & (<<p))
{
bit[p]++; return ;
}
p--;
} return ;
} int main(void) //ZOJ 3870 Team Formation
{
//freopen ("B.in", "r", stdin); int t, n;
scanf ("%d", &t);
while (t--)
{
memset (bit, , sizeof (bit));
scanf ("%d", &n);
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]); solve (a[i]);
} long long ans = ;
for (int i=; i<=n; ++i)
{
int p = ;
while (p >= )
{
if (a[i] & (<<p)) break;
p--;
}
while (p >= )
{
if (!(a[i] & (<<p))) ans += bit[p];
p--;
}
} printf ("%lld\n", ans);
} return ;
}

位运算 ZOJ 3870 Team Formation的更多相关文章

  1. Zoj 3870——Team Formation——————【技巧,规律】

    Team Formation Time Limit: 3 Seconds      Memory Limit: 131072 KB For an upcoming programming contes ...

  2. ZOJ 3870 Team Formation 贪心二进制

                                                    B - Team Formation Description For an upcoming progr ...

  3. ZOJ 3870 Team Formation 位运算 位异或用与运算做的

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...

  4. ZOJ - 3870 Team Formation(异或)

    题意:给定N个数,求这N个数中满足A ⊕ B > max{A, B})的AB有多少对.(A,B是N中的某两个数) 分析: 1.异或,首先想到转化为二进制. eg:110011(A)和 1(B)- ...

  5. 费用流 ZOJ 3933 Team Formation

    题目链接 题意:两个队伍,有一些边相连,问最大组对数以及最多女生数量 分析:费用流模板题,设置两个超级源点和汇点,边的容量为1,费用为男生数量.建边不能重复建边否则会T.zkw费用流在稠密图跑得快,普 ...

  6. ZOJ 3933 Team Formation

    费用流裸题......比赛的时候少写了一句话....导致增加了很多无用的边一直在TLE #include<cstdio> #include<cstring> #include& ...

  7. ZOJ 3870:Team Formation(位运算&思维)

    Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  8. AndyQsmart ACM学习历程——ZOJ3870 Team Formation(位运算)

    Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...

  9. zoj--3870--Team Formation(位运算好题)

    Team Formation Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

随机推荐

  1. 用了那么久居然没发现firefox快捷键有如此多

    firefox用了也有好几年了,除了ytkah经常用到的搜索Ctrl+F.加入书签Ctrl+D.打开新便签Ctrl+T,鼠标右键菜单,还安装了鼠标手势插件FireGestures,快速关闭标签.撤销关 ...

  2. 小白科普之JavaScript的JSON

    一.对json的理解     json是一种数据格式,不是一种编程语言,json并不从属于javascript.     json的语法可以表示以下三种类型的值     1)简单值           ...

  3. [Effective JavaScript笔记]第3条:当心隐式的强制转换

    js对类型错误出奇的宽容 3+true;  //4 3*””;  //0 3+[]; //3 3+[3]; //33 以上表达式在许多语言早就变红了.而js不但不报错还给你个结果. 极少情况会产生即时 ...

  4. Vmware怎样使用nat和桥接方式解决虚拟机联网问题

    对于很多的linux初学者来说,最开始学习linux时通常是在虚拟机上进行的,然而对于新手来说虚拟机联网会对他们来说是比较困难的.这里我根据自己的经验写了一篇文档分享给大家.下面对几种连接方式进行简单 ...

  5. 【Hibernate】Hibernate系列1之概述

    概述 Hibernate简介 1.2.安装hibernate tools插件 1.3.HelloWorld示例 1.3.1.加入jar包 1.3.2.开发步骤 hibernate generator ...

  6. Unique Binary Search Trees I & II

    Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Example Gi ...

  7. EtherCAT数据帧结构

    EtherCAT数据直接使用以太网数据帧(以太网帧解释http://blog.chinaunix.net/uid-23080322-id-118440.html)传输,使用的帧类型为0x88A4.Et ...

  8. smarty模版出现错误提示出现了不期望的字符

    2013年7月5日 08:38:49 提示 unexpected "字符或字符串" 查找前边的代码,看是否有字符串单引号或双引号没有成对出现的情况

  9. 【python】choice函数

    来源:http://www.runoob.com/python/func-number-choice.html 描述 choice() 方法返回一个列表,元组或字符串的随机项. 语法 以下是 choi ...

  10. JDK1.7 HashMap 源码分析

    概述 HashMap是Java里基本的存储Key.Value的一个数据类型,了解它的内部实现,可以帮我们编写出更高效的Java代码. 本文主要分析JDK1.7中HashMap实现,JDK1.8中的Ha ...