ZOJ - 3870-Team Formation二进制,位运算
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870
题意:找出一个数列中的两个数,所有通过异或和使得结果同时大于这两个数;
思路:先找出每个数在二进制下最高位 1 所在的下标;
对于每个数,
1/ 判断这个数的最后一位是不是 0,如果是 0,说明可以 和 最高位是这个位子(1)的数进行异或得到更大的数;
结果加上有多少个这样的数;
2/ 对这个数进行( >>1 ), 右移一位的操作;
ac代码
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
int a[maxn],sum[];
int get(int n)
{
int s=n,re=;
while(s)
{
s>>=;
re++;
}
return re;
}
int main(){
//freopen("in","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum[get(a[i])]++;
}
long long ans=;
for(int i=;i<=n;i++)
{
int wei=;
while(a[i])
{
if((a[i] & )== )
{
ans+=sum[wei];
}
a[i]>>=;
wei++;
}
}
printf("%lld\n",ans);
} return ;
}
ZOJ - 3870-Team Formation二进制,位运算的更多相关文章
- 位运算 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^ ...
- ZOJ 3870:Team Formation(位运算&思维)
Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
- ZOJ 3870 Team Formation 贪心二进制
B - Team Formation Description For an upcoming progr ...
- Zoj 3870——Team Formation——————【技巧,规律】
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contes ...
- AndyQsmart ACM学习历程——ZOJ3870 Team Formation(位运算)
Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...
- 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)- ...
- 面试必备:高频算法题终章「图文解析 + 范例代码」之 矩阵 二进制 + 位运算 + LRU 合集
Attention 秋招接近尾声,我总结了 牛客.WanAndroid 上,有关笔试面经的帖子中出现的算法题,结合往年考题写了这一系列文章,所有文章均与 LeetCode 进行核对.测试.欢迎食用 本 ...
- zoj--3870--Team Formation(位运算好题)
Team Formation Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- UVA 213 信息解码(二进制&位运算)
题意: 出自刘汝佳算法竞赛入门经典第四章. 考虑下面的01串序列: 0, 00, 01, 10, 000, 001, 010, 011, 100, 101, 110, 0000, 0001, …, 1 ...
随机推荐
- 【iOS】the executable was signed with invalid entitlements
又遇到了这个问题,貌似之前遇到过,如图所示: 原因:开发证书里没添加手机. PS: Xcode7 除外,据说已经不需要证书了,这里用的是 6.4
- Java编程思想之十七 容器深入研究
17.1 完整的容器分类方法 17.2 填充容器 import java.util.*; class StringAddress { private String s; public StringAd ...
- 9、数组中删除元素(test6.java)
前文讲到,通过函数,进行数组元素的添加,这里同样通过这个函数,进行数组的删除. 举个例子,代码如下: //导入输入所需要的包 import java.util.Scanner; public clas ...
- Guava cache使用总结
缓存分为本地缓存和远端缓存.常见的远端缓存有Redis,MongoDB:本地缓存一般使用map的方式保存在本地内存中.一般我们在业务中操作缓存,都会操作缓存和数据源两部分.如:put数据时,先插入DB ...
- 微信分享(移动web端)
create-at 2019-02-16 引入微信JS-SDK http://res.wx.qq.com/open/js/jweixin-1.4.0.js (当前最新版本) js 相关代码 (移动端实 ...
- (一)c#Winform自定义控件-基类控件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- kvm 内部错误:无法找到适合 x86_64 的模拟器
0x00 问题 安装完 KVM 之后,启动管理工具报错:内部错误:无法找到适合 x86_64 的模拟器 于是查看 libvirtd 服务状态,查看到以下内容: 6月 14 10:18:53 local ...
- vscode 支持 threejs 的智能提示
VSCode Typings and Intellisense: Dummy Learning VS-Code 1 Jun 20, 2016 Updated on Jun 20 2016 for 1. ...
- Scrapy爬虫框架学习
一.Scrapy框架简介 1. 下载页面 2. 解析 3. 并发 4. 深度 二.安装 linux下安装 pip3 install scrapy windows下安装 a.pip3 install w ...
- 一.安全NA之syslog SNMP SSH NTP
一.常用命令 配置模式下: no logging console #关闭屏幕实时显示日志,不影响到日志buffer里(show logging) logging console #打开屏幕实时日志显示 ...