zoj 3870
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5518
题意:n个数,从中选出两个数,问这两个数的异或值大于两个数较大的数的组合有多少种
题目分类:异或
代码:
#include<bits/stdc++.h> using namespace std; const int MaxN = 1e5 + ;
int a[MaxN], bit[]; // bit[i]表示有多少个数的最高位的1在第i位上 void solve(int x)
{
int l = ;
while(l >= )
{
if(x & (<<l))
{
bit[l]++;
return ;
}
l--;
}
return ;
} int main()
{
int T, n;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
memset(bit, , sizeof(bit));
for(int i = ; i < n; i++)
{
scanf("%d", &a[i]);
solve(a[i]);
}
int ans = ;
for(int i = ; i < n; i++)
{
int l = ;
while(l >= )
{
if(a[i] & (<<l)) break;
l--;
}
while(l >= )
{
if(!(a[i] & (<<l))) ans += bit[l];
l--;
}
}
printf("%d\n", ans);
}
return ;
}
zoj 3870的更多相关文章
- 位运算 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^ ...
- (二进制 异或)Team Formation --ZOJ --3870
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870 http://acm.hust.edu.cn/vjudge/ ...
- 【ZOJ 3870】 Team Formation
题意 n个数,找出有几对a.b 符合 a ^ b > max(a,b) .^表示异或号 分析 对于数a,如果它的二进制是: 1 0 1 0 0 1,那么和它 ^ 后 能比他大的数就是: 0 1 ...
- 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 3870:Team Formation(位运算&思维)
Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- Codeforces Round #272 (Div. 2)AK报告
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- textarea内容有换行时存入数据库丢失问题的解决 (转载)
http://blog.csdn.net/zhang_j_h/article/details/44563167 存入: function GetInputData(id, cmd) { var pos ...
- IOS7上呈现IOS6的水滴刷新效果
IOS7上呈现IOS6的水滴刷新效果 到了IOS7 发现自带的刷新 不再是 IOS6自带的水滴效果了 你是否怀念那IOS6的效果呢? 哈哈,于是收集各方资料,整理编写一个属于自己的水滴刷新效果 ...
- 如何查看VS中预设的路径变量
类似"$(VCInstallDir)"之类的变量查询方法为:打开VS命令行提示窗口,输入 Set 命令. VS中“Tool” - “Visual Studio Command Pr ...
- Debian安装Nexus
前置条件 安装jdk (如果使用 nexus-2.6 以上版本需要jdk7) 1 apt-get install openjdk-6-jre / apt-get install openjdk-6-j ...
- java实现文件传输
在windows下装了个linux虚拟机,两者之间传输文件挺麻烦的.写了个简单的文件传输程序,来方便自己数据传送. server 端: import java.io.BufferedReader;im ...
- 08-使用for循环输出杨辉三角(循环)
/** * 使用循环输出杨辉三角 * * */ public class Test6 { public static void main(String[] args) { // 创建二维数组 int ...
- FindChildControl与FindComponent
前两天编码遇到了要使用FindChildControl方法获取指定名称的TSpeedButton按钮,结果折腾了半天就是没得结果(基础不扎实,呵呵),于是赶紧搜索了下,补习关于这两个方法的用法. TW ...
- linux中段错误的处理
在 Linux环境下做C语言项目,由于是在一个原有项目基础之上进行二次开发,而且项目工程庞大复杂,出现了不少问题,其中遇到最多.花费时间最长的问题就是著名的“段错误”(Segmentation Fau ...
- Java 实现观察者(Observer)模式
1. Java自带的实现 类图 /** * 观察目标 继承自 java.util.Observable * @author stone * */ public class UpdateObservab ...