Educational Codeforces Round 15 Powers of Two
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的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- 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 ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 B
B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 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 ...
随机推荐
- 深入理解html5系列-文本标签
转:http://blog.csdn.net/lihui130135/article/details/45150501 文章简介: 关于html5相信大家早已经耳熟能详,但是他真正的意义在 ...
- 初识boost之boost::share_ptr用法
boost中提供了几种智能指针方法:scoped_ptr shared_ptr intrusive_ptr weak_ptr,而标准库中提供的智能指针为auto_ptr. 这其中,我最喜欢,使用最多的 ...
- python三种数据库连接池方式
psycopg2.pool – Connections pooling Creating new PostgreSQL connections can be an expensive operatio ...
- oracle schema object
Oracle supplies many PL/SQL packages with the Oracle server to extend database functionality and pro ...
- ios 企业发布
ios 1. 支持的tls 协议 1.2 windows server 默认没有启用 检测的网站: https://www.ssllabs.com/ssltest 解决的方法: IIS crypto ...
- expression encoder 4 安装 出现“已经安排重启您的计算机
问题: expression encoder 4 安装 出现“已经安排重启您的计算机 解决的办法,注册表数据的修改 开始 运行 regedit HKEY_LOCAL_MACHINE\SYSTEM\C ...
- Python画图形界面
使用QTdesigner 生成.ui文件,输入命令行pyuic4 -o test.py test.ui 在生成的Python文件后面输入下面代码 if __name__=="__main__ ...
- eclipse svn subclipse下载地址
http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 Eclipse 3.x Subclipse release ...
- java通过http调用服务
package test; import java.io.IOException; import org.apache.commons.httpclient.Cookie; import org.ap ...
- MySQL 使用mysqld_multi部署单机多实例详细过程 (转)
随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然 5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统 ...