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/ ...
随机推荐
- autoLyout纯代码适配
前言 1 MagicNumber -> autoresizingMask -> autolayout 以上是纯手写代码所经历的关于页面布局的三个时期 在iphone1-iphone3gs时 ...
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions 素数 难度:0
http://poj.org/problem?id=3006 #include <cstdio> using namespace std; bool pm[1000002]; bool u ...
- LibSVM使用指南
LibSVM使用指南 一. SVM简介 在进行下面的内容时我们认为你已经具备了数据挖掘的基础知识. SVM是新近出现的强大的数据挖掘工具,它在文本分类.手写文字识别.图像分类.生物序列分析等实 ...
- 全国行政区划代码(json对象版)
var area = {"110000":"北京市","110100":"北京市","110101" ...
- iOS开发之App启动原理
iOS程序的启动过程 程序启动的完整过程大致步骤如下: 1.main函数 2.UIApplicationMain * 创建UIApplication对象 * 创建UIApplication的deleg ...
- Oracle GoldenGate 12c中的协同交付(Coordinated Delivery)
OGG 12c中,并行交付有2种模式:集成交付.协同交付.不过集成交付只能针对目标端是oracle数据库(有版本要求)使用,而协同交付则可以在非oracle数据库上使用. 先来看2个问题, l 为什么 ...
- 主线程中一定不能放耗时操作,必须要开子线程,比如下载文件,不然会不让你拿到输入流--报错显示android.os.NetworkOnMainThreadException
1.必须要开子线程来操作耗时操作,android.os.NetworkOnMainThreadException new Thread(new Runnable() { @Override publi ...
- 图表控件Edraw Max免费下载地址
Edraw Max软件能使学生.老师和商务人士创建并发布各种设计图,它是一个集所有功能于一身的图表控件软件,它可以轻松地创建具有专业外观的流程图.组织结构图.网络图.商业演示图.建筑设计图.思维导图. ...
- linux上安装hadoop
机器准备 物理机器 总 共4台,想配置基于物理机的hadoop集群中包括 4 个 节点: 1 个 Master , 3 个 Salve , 节点之间局域网连接,可以相互 ping 通Ip分布 为192 ...
- yii2 sphinx Ajax搜索分页 关键词的缓存
控制器层 <?php namespace frontend\controllers; use Yii; use yii\web\Controller; //use frontend\models ...