码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ-3870 Team Formation

时间:2016-04-16 22:57:58      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

题目大意:给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

标签:

原文地址:http://www.cnblogs.com/20143605--pcx/p/5399530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!