题目大意:给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的更多相关文章

  1. 位运算 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^ ...

  2. Zoj 3870——Team Formation——————【技巧,规律】

    Team Formation Time Limit: 3 Seconds      Memory Limit: 131072 KB For an upcoming programming contes ...

  3. ZOJ 3870 Team Formation 贪心二进制

                                                    B - Team Formation Description For an upcoming progr ...

  4. ZOJ 3870 Team Formation 位运算 位异或用与运算做的

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...

  5. ZOJ - 3870 Team Formation(异或)

    题意:给定N个数,求这N个数中满足A ⊕ B > max{A, B})的AB有多少对.(A,B是N中的某两个数) 分析: 1.异或,首先想到转化为二进制. eg:110011(A)和 1(B)- ...

  6. 费用流 ZOJ 3933 Team Formation

    题目链接 题意:两个队伍,有一些边相连,问最大组对数以及最多女生数量 分析:费用流模板题,设置两个超级源点和汇点,边的容量为1,费用为男生数量.建边不能重复建边否则会T.zkw费用流在稠密图跑得快,普 ...

  7. ZOJ 3933 Team Formation

    费用流裸题......比赛的时候少写了一句话....导致增加了很多无用的边一直在TLE #include<cstdio> #include<cstring> #include& ...

  8. ZOJ 3870:Team Formation(位运算&思维)

    Team Formation Time Limit: 2 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  9. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  10. 第十二届浙江省大学生程序设计大赛-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 ...

随机推荐

  1. 可以创建专业的客户端/服务器视频会议应用程序的音频和视频控件LEADTOOLS Video Conferencing SDK

    LEADTOOLS Video Streaming Module控件为您创建一个自定义的视频会议应用程序和工具提供所有需要的功能.软件开发人员可以使用Video Streaming Module SD ...

  2. 2799元的HTC One时尚版要卖疯了

    俗话说“好人有好报”,这句话同样可以应用到手机上.本月初,HTC正式公布了HTC One时尚版的售价,裸机2799元,礼包价2999元(配智能立显保护套).该价格一出,立刻引来一片哗然.因为大家都不相 ...

  3. UIButton 点击后变灰

    +(UIButton *)getBlueButtonWithTitle:(NSString *)aTitle{ UIButton *button = [UIButton buttonWithType: ...

  4. 简单的php Mysql类(查询 删除 更新)

    php Mysql类一般都包括了几乎我们常用的数据库操作方法,这里只提供了查询 删除 更新三种操作,算不是很全只是一个简单的数据库查询类了.      代码如下 复制代码 class mysql { ...

  5. FMDB数据库中的一些操作

    #pragma mark - 数据库的操作 - (BOOL)judgeModel:(TaskResourceModel *)model isInArray:(NSArray *)shopArray { ...

  6. Ogre中OctreeSceneManager

    转自:http://blog.csdn.net/yanonsoftware/article/details/1067265 既然前面分析Mesh(Entity,SceneNode)的渲染时已经看到了O ...

  7. SwipeRefreshLayout

    也许之前下拉刷新你可能会用到一些第三方开源库,如PullToRefresh, ActionBar-PullToRefresh.XlistView等 但现在已经有官方的组件了---SwipeRefres ...

  8. ubuntu  输入时弹出剪切板候选项

    fcitx很坑的把这个功能的快捷键设置成了ctrl + ;结果我在用vim的时候怎么也 没法输入command 不知道是哪次更新引入的,简直是坑人! 我找了半天系统设置都没找到这个快捷键是在哪设置的. ...

  9. 一、XML语法

    xml声明xml指令:<? ?>xml编码与乱码xml元素(标签)CDATA区空格与换行会被认为是标签的内容xml-stylesheet指令解析xml内容 <?xml version ...

  10. @synthesize的使用

    利用@synthesize可以给在.m文件中给.h文件中的属性重新定义新的名称如 @synthesize firstname = anothername:firstname是在.h文件中定义的,新定义 ...