Powers of Two

题意:

让求ai+aj=2的x次幂的数有几对,且i < j。

题解:

首先要知道,排完序对答案是没有影响的,比如样例7 1一对,和1 7一对是样的,所以就可以排序之后二分找2的x次幂相减的那个数就好了,注意:打表时2的x次幂不能只小于1e9,因为有可能是2个5e8相加,之后就超出了1e9,但是你打表的时候又没有超出1e9的那个2的x次幂,所以答案总是会少几个。所以尽量就开ll 能多打表就多打。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
#define PU puts("");
#define PI(A) cout<<A<<endl
#define SI(N) cin>>N
#define SII(N,M) cin>>N>>M
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
#define dbg(x) cout <<#x<<" = "<<x<<endl
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS= 1e-9 ; /* ///////////////////////// C o d i n g S p a c e ///////////////////////// */ const int MAXN= 100000 + 9 ; int a[MAXN];
int N; int main()
{ iostream::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll pow2[50]={1};
int cnt=1;
Rep(i,1,35)
{
pow2[cnt++]=2*pow2[i-1];
}
while(SI(N))
{
rep(i,N) SI(a[i]);
sort(a,a+N);
ll ans=0;
rep(i,N-1)
{
Rep(j,0,35)
{
ll d=pow2[j]-a[i];
if (d<=0) continue;
ll num=lower_bound(a+i+1,a+N,d+1)-lower_bound(a+i+1,a+N,d);
ans+=num;
}
}
PI(ans);
}
return 0;
}

Educational Codeforces Round 15 Powers of Two的更多相关文章

  1. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  4. Educational Codeforces Round 15 A, B , C 暴力 , map , 二分

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. Educational Codeforces Round 15 B

    B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  8. Educational Codeforces Round 15 A dp

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

随机推荐

  1. POJ 1469 COURSES(二部图匹配)

                                                                     COURSES Time Limit: 1000MS   Memory ...

  2. POJ-1655 Balancing Act

    题目大意:一棵n个节点的树,找出最大子树最小的节点. 题目分析:过程类似求重心. 代码如下: # include<iostream> # include<cstdio> # i ...

  3. spring源码学习之:xml标签扩展配置例子

    在很多情况下,我们需要为系统提供可配置化支持,简单的做法可以直接基于Spring的标准Bean来配置,但配置较为复杂或者需要更多丰富控制的 时候,会显得非常笨拙.一般的做法会用原生态的方式去解析定义好 ...

  4. 用Spring的mappingDirectoryLocations来配置Hibernate映射文件

    在Spring的applicationContext.xml中配置映射文件的方法: <property name="mappingResources">     < ...

  5. 时事新闻之 谷歌 google 发布Tensor Flow 源代码

    TensorFlow: TensorFlow is an open source software library for numerical computation using data flow ...

  6. linq中AsEnumerable和AsQueryable的区别

    本文导读:用Linq来操作集合的时候会用到AsQueryable()和AsEnumerable(),何时该用AsQueryable()和何时该用AsEnumerable(),或许存在些疑惑.AsQue ...

  7. 在Discuz中增加创始人

    第一步 在 /config/config_uccenter.php 中 修改 $_config['admincp']['founder'] = '用户UID,用户UID2';   第二步 在 UPDA ...

  8. ibm硬件知识点

    ibm http://www-03.ibm.com/systems/storage/disk/storwize_v3700/index.html Current software level: Ver ...

  9. 最短路径—Dijkstra算法和Floyd算法【转】

    本文来自博客园的文章:http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html Dijkstra算法 1.定义概览 Dijk ...

  10. Oracle无法启动,ORA-01034、ORA-01078

    因为调整32位系统的SGA区大小时不慎,超出可用内存,造成Oracle实例无法启动,报出ORA-01034.ORA-01078等错误.如下图 sqlplus /nolog SQL> conn / ...