位运算 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 ...
随机推荐
- bc.34.B.Building Blocks(贪心)
Building Blocks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- [Unity3D]计时器/Timer
原地址:http://blog.sina.com.cn/s/blog_5b6cb9500101aejs.html https://github.com/xuzhiping7/Unity3d-Timer ...
- VS2008+Qt+助手 智能提示不显示、Qt关键字不高亮的解决办法【已解决】
笔者使用的开发环境是VS2008+Qt4.8.5+VAssistX,有时候会出现代码关键字不能高亮显示,并且助手的智能提示不显示.问题如下 解决的办法是在助手的选项中设置其搜索路径,助手的设置通过VS ...
- 国内常用NTP服务器地址及IP
iptables实现80端口转发到8080端口上 iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 ...
- NYOJ 38布线问题
http://acm.nyist.net/JudgeOnline/problem.php?pid=38 布线问题 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 南阳 ...
- TCP/IP详解学习笔记(5)-- ICMP:internet 控制报文协议
1.概述 ICMP是(Internet Control Message Protocol)Internet控制报文协议.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制 ...
- Flip Game I && II
Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...
- object-c 基本数据类型
1.基本数据类型 int float double char 布尔类型 枚举类型 2.对象类型和id类型 就是类类型或协议所声明的指针类型. id类型可以表示任何类型,一般只表示 ...
- 排序稳定性stable
stable排序 O(n^2): InsertionSort,BubbleSort O(nlgn): MergeSort O(n+k): CountSort, RadixSort,BucketSort ...
- 70 数组的Kmin算法和二叉搜索树的Kmin算法对比
[本文链接] http://www.cnblogs.com/hellogiser/p/kmin-of-array-vs-kmin-of-bst.html [分析] 数组的Kmin算法和二叉搜索树的Km ...