codeforces-Powers of Two(map的应用)
来源:互联网 发布:c语言智能五子棋游戏 编辑:程序博客网 时间:2024/06/06 04:43
B. Powers of Two
time limit per test
3 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer xexists so that ai + aj = 2x).
Input
The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
Examples
input
47 3 2 1
output
2
input
31 1 1
output
3
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<map>#include<queue>#include<algorithm>using namespace std;int main(){__int64 a[100005],sum=0;int b[33]; b[1]=2;for(int i=2;i<=30;i++) b[i]=b[i-1]*2;map<int,int>p;int n,i,j;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%I64d",&a[i]);for(j=1;j<=30;j++){if(b[j]-a[i]<0 || p.count(b[j]-a[i])==0)continue;sum+=p[b[j]-a[i]];}p[a[i]]++;}printf("%I64d\n",sum);}
0 0
- codeforces-Powers of Two(map的应用)
- Codeforces 702 B. Powers of Two(二分)
- CodeForces 702B Powers of Two(二分)
- 【CodeForces】702B - Powers of Two(二分)
- 【Codeforces】-702B-Powers of Two(二分)
- Educational Codeforces Round 15 B. Powers of Two (数学)
- CodeForces 702B: Powers of Two(遍历、穷举)
- Codeforces 702B - Powers of Two
- codeforces-702B-Powers of Two
- CodeForces 702B Powers of Two
- Codeforces 702B. Powers of Two
- codeforces 702B - Powers of Two
- hihocoder#1410 : Powers of Two(水题)
- Libgdx powers of two
- CodeForces702B Powers of Two
- codeforces 305 C. Ivan and Powers of Two
- CodeForces 305C--Ivan and Powers of Two (STL:set)
- CodeForces 305CIvan and Powers of Two【set】
- 经验如何提高PHP执行效率的50个技巧
- HDU5763 Another Meaning动态规划
- HDU 5710 Digit-Sum
- iOS线程和进程的区别和联系
- 多线程的作用和实现方法
- codeforces-Powers of Two(map的应用)
- LightOJ1129->动态Trie树
- 在Windows下为PHP5.5安装redis扩展
- 百练 2624 4th Point .
- 三字棋小游戏
- svo简单探讨1
- HDU 4417-树状数组求区间rank查询/主席树区间rank查询
- Android Stdio安装与使用
- Linux 学习【2】