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 ...
随机推荐
- 第n小的质数
总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个正整数n,求第n小的质数. 输入 一个不超过10000的正整数n. 输出 第n小的质数. 样例输入 10 样例输出 29 代碼 ...
- NOIP2016 D1T1 玩具迷題(toy)
题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业. 有一天, 这些玩具小人把小南的眼镜藏了起来. 小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外.如下图: 这时singer告诉 ...
- ls命令大全
ls 命令:15个Linux面试级问题--第一集 [日期:2015-03-12] 来源:Linux社区 作者:GuiltyMan [字体:大 中 小] 注释:'ls'是“list”的意思,重点在 ...
- ABB机器人添加串口模块后无法使用的解决办法
[环境] ABB机器人1520,IRC5,RobotWare5.6,Win10 64bits,RobotStudio6.0 [过程和表现] 由于项目需要和机器人通信,DeviceNet又不能满足要求, ...
- PHP-关于$_SERVER
类似于Nginx中的请求头,所有header,都可以使用 $http_xxx来使用,比如$http_accept,甚至包括自定义的,比如,$http_x_forwarded_host proxy_se ...
- 11g RAC日志体系(cluster,database,asm,scan日志,ADRCI工具的使用)
- XunSearch(讯搜)的使用教程步骤
一.安装编译工具 yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel ...
- addClass的用法和is函数的用法
<html> <head> <meta charset="utf-8"> <script type="text/javascri ...
- 关于$.ajax中data字段的整理--包括json转换和spring注解
1.前端$.ajax 的data为json提交的时候,后台方法中必须使用@RequestBody 注解 @RequestMapping(value = "getCpuData/{int ...
- 谷歌 analytics.js 部分解密版
源:http://www.google-analytics.com/analytics.js (function(){var aa=encodeURIComponent,f=window,ba=set ...