CF 702B Powers of Two(暴力)
题目链接: 传送门
Devu and Partitioning of the Array
time limit per test:3 second memory limit per test:256 megabytes
Description
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 = 2^x).
Input
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 10^9).
Output
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
Sample Input
4
7 3 2 1
3
1 1 1
Sample Output
2
3
解题思路
注意到2^31次方就能达到10^9级别,所以枚举的时候枚举2的幂次方而不是枚举N,枚举N果断超时。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef __int64 LL;
int main()
{
int N;
while (~scanf("%d",&N))
{
LL tmp,res = 0;
map<LL,LL>mp;
for (int i = 0;i < N;i++)
{
scanf("%I64d",&tmp);
for (int j = 1;j < 32;j++)
{
if (mp.find((1<<j)-tmp) != mp.end())
{
res += mp[(1<<j)-tmp];
}
}
mp[tmp]++;
}
printf("%I64d\n",res);
}
return 0;
}
CF 702B Powers of Two(暴力)的更多相关文章
- CodeForces 702B Powers of Two (暴力,优化)
题意:给定 n 个数,问你从有多少下标 i < j,并且 ai + aj 是2的倍数. 析:方法一: 从输入开始暴力,因为 i < j 和 i > j 是一样,所以可以从前面就开始查 ...
- CF 1095C Powers Of Two(二进制拆分)
A positive integer xx is called a power of two if it can be represented as x=2y, where y is a non-ne ...
- CodeForces 702B Powers of Two【二分/lower_bound找多少个数/给出一个数组 求出ai + aj等于2的幂的数对个数】
B. Powers of Two You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, ...
- CF 1095C Powers Of Two
题目连接:http://codeforces.com/problemset/problem/1095/C 题目: C. Powers Of Two time limit per test 4 seco ...
- cf 702B
You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that a ...
- CodeForces 702B Powers of Two
简单题. 开一个$map$记录一下每个数字出现了几次,那么读入的时候$f[a[i]]+1$. 计算$a[i]$做出的贡献的时候,先把$f[a[i]]-1$,然后再枚举$x$,答案加上$f[{2^x} ...
- CF 305A——Strange Addition——————【暴力加技巧】
A. Strange Addition time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CF 568A(Primes or Palindromes?-暴力推断)
A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- 洛谷P4117 [Ynoi2018]五彩斑斓的世界 [分块,并查集]
洛谷 Codeforces 又是一道卡常题-- 思路 YNOI当然要分块啦. 分块之后怎么办? 零散块暴力,整块怎么办? 显然不能暴力改/查询所有的.考虑把相同值的用并查集连在一起,这样修改时就只需要 ...
随机推荐
- 发布我的图片预加载控件YPreLoadImg v1.0
介绍 大家好!很高兴向大家介绍我的图片预加载控件YPreLoadImg.它可以帮助您预加载图片,并且能显示加载的进度,在预加载完成后调用指定的方法. YPreLoadImg控件由一个名为PreLoad ...
- 前端科普文—为什么<!DOCTYPE> 不可或缺
When question comes 你一定在 HTML 页面最前面看到过这样一行代码(比如 百度): <!DOCTYPE html> 或者说类似这样的(比如 博客园-韩子迟 PS:博客 ...
- Bootstrap系列 -- 4. 文本内容强调
一. 文本强调基本样式 .text-muted:提示,使用浅灰色(#999) .text-primary:主要,使用蓝色(#428bca) .text-success:成功,使用浅绿色(#3c763d ...
- extjs 箱子布局
a.flex 配置项 flex 配置项不是设置在布局上,而是设置在子项的配置项.每个子项相对的 flex 值都会与全体子项 flex 累加的值相比较,根据此结果,处理每个子项的 flex 最后是多少. ...
- Linux_脚本安装包(以Webmin的安装为例)
1.Webmin下载地址:https://sourceforge.net/projects/webadmin/files/webmin/ 版本使用1.820 2.解压Webmin ...
- 【BZOJ 1043】【HNOI 2008】下落的圆盘 判断圆相交+线段覆盖
计算几何真的好暴力啊. #include<cmath> #include<cstdio> #include<cstring> #include<algorit ...
- Self Host WebApi服务传输层SSL加密(服务器端+客户端调用)
接上篇<WebApi服务URI加密及验证的两种方式>,在实际开发中,仅对URI进行加密是不够的,在传输层采用SSL加密也是必须的. 如果服务寄宿于IIS,那对传输层加密非常简单仅需要配置一 ...
- poi-处理excel的单元格日期数据
poi处理excel时,当excel没有明确指明是哪个类型的数据时,poi很可能处理单元格的日期数据时就有可能是一串数字.而使用java程序基本无法转换 以下为对poi处理日期情况一些方面的处理(不是 ...
- java.net.URLConnectioin的http(get,post)请求(原生)
使用Java发送这两种请求的代码大同小异,只是一些参数设置的不同.步骤如下: 通过统一资源定位器(java.net.URL)获取连接器(java.net.URLConnection) 设置请求的参数 ...
- java eclipse打jar包和执行jar中的main函数
jar包使用eclipse打包步骤 右键需要打包的项目->选择Export 到这里有两种打包的方式 1.如果项目中没有使用其他第三方包等,则直接选择下图中的第一种即可(JAR file) 2.如 ...