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/ ...
随机推荐
- WP8 学习 Onnavigatedto和OnnavigatedFrom的区别
OnNavigatedTo:重写 OnNavigatedTo 方法以检查导航请求并且准备供显示的页面.这个方法就像是初始化(Ini) ,它先于Loaded事件之前被执行,所以在这里可以控制一些初始化前 ...
- [windows驱动]基本概念
https://msdn.microsoft.com/zh-cn/library/windows/hardware/ff554721 1.设备节点和设备堆栈 在windows中,设备通过即插即用设备树 ...
- JS 获取当前浏览器类型
JS代码: function getType() { if(navigator.userAgent.indexOf("MSIE")>0) { return "MSI ...
- webview调用外部浏览器而不是在控件中显示
view.loadUrl(url); // 如果页面中链接,如果希望点击链接继续在当前browser中响应, // 而不是新开Android的系统browser ...
- 关于dllimport的使用
最近做一个动态加载插件的项目,插件中的dll 主要是各厂商各型号的读卡器的通用类库,stdapi.dll,WltRS.dll,有的还有进一步封装的dll,主要是为了简化通用类库的操作. 这些类库都是用 ...
- Tab切换栏
// Tab切换栏 function setTab(name, m, n) { for (var i = 1; i <= n; i++) { var menu = document.getEle ...
- (转)HTML5开发学习(2):本地存储之localStorage 、sessionStorage、globalStorage
原文:http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416386.html HTML5开发学习(2):本地存储之localStorage ...
- fix eclipse gc overhead limit exceeded in mac
fix eclipse gc overhead limit exceeded: 在mac上找不到eclipse.ini文件编辑内存限制,在eclipse安装目录右击eclipse程序,选“显示包内容” ...
- hdu 2047
PS:又是上课偷懒..去递推.. 代码: #include "stdio.h"#include "math.h"long long dp[55];long lo ...
- windows程序设计笔记
2014.05.06 新建一个visual C++ -- 常规 -- 空白 的项目,用.c后缀名指定这是一个用C语言来写的windows项目.和C语言的hellworld程序做了一个比较,按照wind ...