Educational Codeforces Round 15 B
3 seconds
256 megabytes
standard input
standard output
You 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 x exists so that ai + aj = 2x).
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).
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
4
7 3 2 1
2
3
1 1 1
3
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).
In the second example all pairs of indexes (i, j) (where i < j) include in answer.
题意:给你n个数 问你有多少对 数的和为2^x
题解:标记每个数 枚举2^x 与a[i]取差值 统计mp[2^x-a[i]] 注意ans/2 注意开LL
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int n;
int a[];
map<int,int>mp;
int main()
{
scanf("%d",&n);
mp.clear();
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
mp[a[i]]++;
}
int exm=;
ll ans=;
for(int i=; i<=; i++)
{
exm=exm<<;
for(int j=; j<=n; j++)
{
if(mp[exm-a[j]])
{
mp[a[j]]--;
ans=ans+mp[exm-a[j]];
mp[a[j]]++;
}
}
}
cout<<ans/<<endl;
return ;
}
Educational Codeforces Round 15 B的更多相关文章
- 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 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 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 ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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 [111110]
注意一个词:连续 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<bits/ ...
随机推荐
- hdu 4631 Sad Love Story
http://acm.hdu.edu.cn/showproblem.php?pid=4631 没想到这道题需要用“平均时间复杂度” 计算 一直没有想到解法 因为不符考虑了最坏情况的理念 方法一: ...
- 使用ROS节点(五)
先启动roscore roscore 为了获取节点信息,可以使用rosnode命令 $ rosnode 获取得一个可接受参数清单
- as3基础知识
在AS3中,值类型数据(简单类型:Boolean.int.Number.String.uint)和引用类型数据(复杂类型)都是 对象,所以这两种类型对象存储的都是引用.但是,对应值类型数据,是一种不变 ...
- BT3入门之中文语言支持
汉化: 1.更新软件库:apt-get update 2.安装中文语言包:apt-get install language-support-zh apt-get install language- ...
- java,android获取系统当前时间
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss ");Date curDate = ...
- jquery的is用法
JQuery 中 is(':visible') 解析及用法 javascript代码$(document).ready(function() { $('#faq').find('d ...
- PAT 10-2 删除字符串中的子串
今天发一个不完全对(通过garbageMan园友的帮忙,现已全对)的代码,(/*后两用例未通过,一时看不出问题在哪,*/)切入正题 /* Name: Copyright: Author: Date: ...
- Android Context
http://www.cnblogs.com/android100/p/Android-Context.html
- ant新建scp和sshexec任务
1.build.xml中新建targer如下: <target name="remotecopytest" description="拷贝文件到远程服务器" ...
- os.system和os.popen
使用os.popen调用test.sh的情况: python调用Shell脚本,有两种方法:os.system(cmd)或os.popen(cmd),前者返回值是脚本的退出状态码,后者的返回值是脚本执 ...