位运算 ZOJ 3870 Team Formation
/*
题意:找出符合 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的更多相关文章
- Zoj 3870——Team Formation——————【技巧,规律】
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- ZOJ 3870 Team Formation 贪心二进制
B - Team Formation Description For an upcoming progr ...
- ZOJ 3870 Team Formation 位运算 位异或用与运算做的
For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...
- ZOJ - 3870 Team Formation(异或)
题意:给定N个数,求这N个数中满足A ⊕ B > max{A, B})的AB有多少对.(A,B是N中的某两个数) 分析: 1.异或,首先想到转化为二进制. eg:110011(A)和 1(B)- ...
- 费用流 ZOJ 3933 Team Formation
题目链接 题意:两个队伍,有一些边相连,问最大组对数以及最多女生数量 分析:费用流模板题,设置两个超级源点和汇点,边的容量为1,费用为男生数量.建边不能重复建边否则会T.zkw费用流在稠密图跑得快,普 ...
- ZOJ 3933 Team Formation
费用流裸题......比赛的时候少写了一句话....导致增加了很多无用的边一直在TLE #include<cstdio> #include<cstring> #include& ...
- ZOJ 3870:Team Formation(位运算&思维)
Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- AndyQsmart ACM学习历程——ZOJ3870 Team Formation(位运算)
Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...
- zoj--3870--Team Formation(位运算好题)
Team Formation Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
随机推荐
- wordpress自定义后台用户联系方式 添加qq、微博、微信
在 WordPress 后台,个人设置(Profile)中,可以设置电子邮件和 Website,如何添加国人常用的 QQ, 微博,微信呢? <?php /* Plugin Name: Custo ...
- php面试题之二——数据结构和算法(高级部分)
二.数据结构和算法 1.使对象可以像数组一样进行foreach循环,要求属性必须是私有.(Iterator模式的PHP5实现,写一类实现Iterator接口)(腾讯) <?php class T ...
- Centos6.5更新e1000网卡驱动
导读 在工作过程中经常遇到linux的操作系统网络不正常的情况,以前没有注意到,今天查看系统日志发现原来是网络驱动的问题.索性直接更新系统,更新网卡 问题:linux系统经常出现断网的情况,重启之后系 ...
- Centos优化Hadoop
导读 Hadoop是一个能够让用户轻松架构和使用的分布式计算平台,用户可以轻松地在Hadoop上开发和运行处理海量数据的应用程序,本节讲安装并且优化centos 6.7 系统下的Supper Hado ...
- hiho一下第88周《Coordinates》
题目大意 给定数字P,Q,求出所有P和Q的约数p,q能够组成的不重复数字对(p,q) 解题思路 作为本场比赛的第一题,本题的难度在于考察选手是否有基本的编程能力. 本题中需要求出P,Q所有约数组成的数 ...
- Linux 实现rsyslog日志里面的IP地址记录 未测试
之前我是在bashrc中添加了一句,让系统操作日志时向rsyslog发送一份内容,现在只要在发送的时候,自己再获取下当前的远程登录IP加进去就可以,像这样 /etc/bashrc sshClientI ...
- django 1.7 新特性 --- data migration
官方文档:https://docs.djangoproject.com/en/dev/topics/migrations/ 1.7 之前大家可能会用south用于管理数据库的模型的同步.1.7之后dj ...
- linux screen 命令详解(未验证+研究)
一.背景 系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份.ftp 传输等等.通常情况下我们都是为每一个这样的任务开一个远 ...
- 同时运行多个scrapy爬虫的几种方法(自定义scrapy项目命令)
试想一下,前面做的实验和例子都只有一个spider.然而,现实的开发的爬虫肯定不止一个.既然这样,那么就会有如下几个问题:1.在同一个项目中怎么创建多个爬虫的呢?2.多个爬虫的时候是怎么将他们运行起来 ...
- window.parent与window.openner 之前的总结
今天总结一下js中几个对象的区别和用法: 1.首先来说说 parent.window与top.window的用法 "window.location.href","loca ...