ZOJ-3870 Team Formation
题目大意:给n个正数,找出满足A^B>max(A,B)的对数。
题目分析:
代码如下:
# include<iostream>
# include<cstdio>
# include<cstring>
# include<vector>
# include<queue>
# include<list>
# include<set>
# include<map>
# include<string>
# include<cmath>
# include<cstdlib>
# include<algorithm>
using namespace std;
# define LL long long const int N=1005;
const int INF=1000000000; int n;
int a[N*100];
int p[N*100]; int getLpos(int l,int r,int x)
{
while(l<r){
int mid=l+(r-l)/2;
if(p[mid]<x)
l=mid+1;
else
r=mid;
}
return l;
} int getRpos(int l,int r,int x)
{
while(l<r){
int mid=l+(r-l)/2;
if(p[mid]>x)
r=mid;
else
l=mid+1;
}
return l;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;++i){
scanf("%d",a+i);
}
sort(a,a+n);
for(int i=0;i<n;++i){
for(int j=31;j>=0;--j){
if(a[i]&(1<<j)){
p[i]=j;
break;
}
}
}
int ans=0;
for(int i=0;i<n;++i){
for(int j=p[i]-1;j>=0;--j){
if(a[i]&(1<<j)) continue;
int l=getLpos(0,i,j);
int r=getRpos(0,i,j);
ans+=r-l;
//cout<<i<<' '<<l<<' '<<r<<endl;
}
}
printf("%d\n",ans);
}
return 0;
}
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: 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 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏
Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...
随机推荐
- C# WebRequestExtensions
https://gist.github.com/abombss/2720757 public static class WebRequestExtensions { public static Htt ...
- CentOS SSH配置
默认CentOS已经安装了OpenSSH,即使你是最小化安装也是如此.所以这里就不介绍OpenSSH的安装了. SSH配置: 1.修改vi /etc/ssh/sshd_config,根据模板将要修改的 ...
- 使用JsonObject解析json
第一种: [ { "0": "1", "1": "一", "id": "1", ...
- 如何搭建MVC + EF 框架
1.搭建MVC框架 1.1 VS2010:需要安装WPI 安装 ASP.NET MVC 4 和Visual Studio 2010 系统必备组件 如果上述链接无法打开,请访问:http://www.a ...
- String的两个API,判断指定字符串是否包含另一字符串,在字符串中删除指定字符串。
// 在字符串中删除指定字符串. String phoneNum="1795112345"; phoneNum = phoneNum.replace("17951&quo ...
- the way of reading English books
除了datesheet ,我们经常遇到英语文档和资料.找到正确的英语文档的打开方式变的非常必要. 计算机类的书大致归为三大类: (1)语言方面的书.比如C.Java.Python等等 (2)算法书籍. ...
- 2016 - 1- 22 HTTP(三)
一: iOS中发送HTTP请求的方案 三: HTTP通信过程 1.请求 1.1 HTTP协议规定,一个完整的有客户端发给服务器的请求应包含以下内容: 1.1.1 请求头: 包含了对客户端环境的描述与 ...
- 《View Programming Guide for iOS》之frame、bounds和center之间的关系
The frame property contains the frame rectangle, which specifies the size and location of the view i ...
- CSS样式选择器
<!-- css样式选择器 HTML选择器 类选择器 ID选择器 关联选择器 组合选择器 伪元素选择器 selector{ /* selector是样式选择器 property:value; / ...
- 20135214万子惠 (2)——-Java面向对象程序设计
实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 (一)单元测试 (1) 三种 ...