标签:
题目大意:给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; }
标签:
原文地址:http://www.cnblogs.com/20143605--pcx/p/5399530.html