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/ ...
随机推荐
- 大过年的,不下班的,上个Android文件操作类(内部存储和sd卡均可)
package com.kkdiangame.UI.res; import java.io.ByteArrayOutputStream; import java.io.File; import jav ...
- sql面向过程用法
sql可以看成是面向过程的编程语言.该语言中,有string.date.table这样的类型等等 一.操作表 sql相当于一个函数,输入是两个或多个表(A, B, ...) 求集合: 并集 union ...
- java.net.SocketException: Too many open files
1.ps -ef|grep java 2.lsof -p 32636 3.lsof -p 20812|wc –l 这个也可以看一个进程打开的文件数 4.ulimit –a c3p0官方提供了两个参 ...
- Javascript使用总结
Javascript(简称JS)简介 JavaScript是一门广泛用于浏览器客户端的脚本语言,由Netspace公司设计,当时跟Sun公司(已经被oracle收购)合作,所以名字起得像Java,业内 ...
- 关于$.getJson
这是一个Ajax函数的缩写,这相当于: 1 2 3 4 5 6 $.ajax({ dataType: "json", url: url, data: data, success: ...
- poj1159 dp最长公共子串
//Accepted 204 KB 891 ms //dp最长公共子串 //dp[i][j]=max(dp[i-1][j],dp[i][j-1]) //dp[i][j]=max(dp[i][j],dp ...
- angularjs 选项卡 --- 自定义属性
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- 如何修改svn的密码或重新输入用户名密码
在Eclipse 使用SVN 的过程中大多数人往往习惯把访问SVN 的用户名密码自动保存起来以便下次自动使用,不要再次手工输入,而此时(自动保存密码后),svn又不存在一个显式的登陆框了,但是有些时候 ...
- (spring-第13回【IoC基础篇】)PropertyEditor(属性编辑器)--实例化Bean的第五大利器
上一篇讲到JavaBeans的属性编辑器,编写自己的属性编辑器,需要继承PropertyEditorSupport,编写自己的BeanInfo,需要继承SimpleBeanInfo,然后在BeanIn ...
- 数据结构 《6》----堆 ( Heap )
Practival Problems: a. Construct a Huffman code b. Compute the sum of a large set of floating point ...