题目传送门

 /*
题意:找出符合 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. cocos基础教程(11)事件分发机制

    cocos3.0的事件分发机制: 创建一个事件监听器-用来实现各种触发后的逻辑. 事件监听器添加到事件分发器_eventDispatcher,所有事件监听器有这个分发器统一管理. 事件监听器有以下几种 ...

  2. xcode arc引起的autorelease报错问题

    http://blog.csdn.net/xiechengfa/article/details/37971223 自从用上了真苹果,一直升级,现在xcode版本是4.4,或者说是ios5 一直有个问题 ...

  3. 异常详细信息: System.Data.SqlClient.SqlException:用户 'IIS APPPOOL\DefaultAppPool' 登录失败解决办法

    1.安全性---登录名---新建登录名 2.常规----搜索 3.添加SERVICE用户-- 4.服务器角色---勾上sysadmin: IIS中: 应用程序池---对应的程序池上右键---高级设置 ...

  4. 【leetcode】Interleaving String

    Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Fo ...

  5. CentOS6.5以runlevel 3开机时自动连接某无线设置示例

    [参考]http://blog.csdn.net/simeone18/article/details/8580592 [方法一] 假设无线网卡代号为wlan0,无线AP的essid为:TheWiFi, ...

  6. volatile关键字

    [本文链接] http://www.cnblogs.com/hellogiser/p/volatile.html [分析] volatile 关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编 ...

  7. linux下重启tomcat、实时查看tomcat运行日志

    在Linux系统下,重启Tomcat使用命令操作的! 首先,进入Tomcat下的bin目录 cd /usr/local/tomcat/bin 使用Tomcat关闭命令 ./shutdown.sh 查看 ...

  8. extjs在窗体中添加搜索框

    在extjs中添加搜索框,搜索框代码如下: this.searchField = new Ext.ux.form.SearchField({            store : this.store ...

  9. 引水入城(codevs 1066)

    题目描述 Description 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政 区划十分特殊,刚好构成一个N行M列的矩形,如上图所示,其中每个格子都代表一座城 市,每座 ...

  10. nginx 匹配.zip .apk 结尾的文件 直接下载

    server { listen 80; server_name ok.xidd.com; index index.html index.htm index.php; root /alidata/www ...