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. python 字符串 大小写转换

    总结 capitalize() 首字母大写,其余全部小写 upper() 全转换成大写 lower() 全转换成小写 title() 标题首字大写,如"i love python" ...

  2. java .net compartion

    1, http://www-01.ibm.com/software/smb/na/J2EE_vs_NET_History_and_Comparison.pdf http://stackoverflow ...

  3. PCA和Softmax分类比较—Mnist与人脸数据集

    PCA人脸识别中三种方法得到的正确率可达到100% 作为对比,单独使用Softmax回归对人脸40*10*92*112的数据分类正确率为97%. 用PCA对MNIST手写数字10*500*28*28识 ...

  4. 由浅入深漫谈margin属性1

    margin 在中文中我们翻译成外边距或者外补白(本文中引用外边距).他是元素盒模型(box model)的基础属性. (该文章解释是否正确有待商榷,目前我的实验结果为:在默认情况或者div左浮动的情 ...

  5. InnoDB Plugin文件格式(概述)

    本文将介绍InnoDB Plugin数据表格式的基本概念. 1. 配置参数innodb_file_format 这是一个很容易混淆的概念.目前,在InnoDB Plugin(1.0.6)配置文件中in ...

  6. sed的实际用法举例

    sed:Stream Editor文本流编辑,sed是一个“非交互式的”面向字符流的编辑器.能同时处理多个文件多行的内容,可以不对原文件改动,把整个文件输入到屏幕,可以把只匹配到模式的内容输入到屏幕上 ...

  7. jQuery.form.js使用

    jQuery.form.js是一个form插件,支持ajax表单提交和ajax文件上传. 下载地址 百度云:http://pan.baidu.com/s/1eQoYE46 360云:http://yu ...

  8. php 错误 Strict Standards: PHP Strict Standards: Declaration of .... should be compatible with that of 解决办法

    错误原因:这是由于 php 5.3版本后.要求继承类必须在父类之后定义.否则就会出现Strict Standards: PHP Strict Standards: Declaration of ... ...

  9. WCF Client is Open Source

    WCF Client is Open Source Wednesday, May 20, 2015 Announcement New Project WCF We’re excited to anno ...

  10. FileDataSource java的文件操作

    FileDataSource:(javax.activation.FileDataSource.FileDataSource(File file)) FileDataSource 类实现一个封装文件的 ...