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当然要分块啦. 分块之后怎么办? 零散块暴力,整块怎么办? 显然不能暴力改/查询所有的.考虑把相同值的用并查集连在一起,这样修改时就只需要 ...
随机推荐
- 前端手札--meta标记篇
通用类: 声明编码 <meta charset='utf-8' /> SEO页面关键词 <meta name="keywords" content="y ...
- .NET MVC AjaxHelper
我们首先必须开启 非入侵式 Ajax:导入Jquery和unobtrusiveAjax文件 已经默认开启客户端验证 和 非侵入式js <add key="ClientValidatio ...
- 【干货分享】JPager.Net MVC超好用轻量级分页控件
JPager.Net MVC好用的轻量级分页控件,好用到你无法想象,轻量到你无法想象. JPager.Net MVC好用的轻量级分页控件,实现非常简单,使用也非常简单. JPager.Net M ...
- 基于DDD的.NET开发框架 - ABP的Entity设计思想
返回ABP系列 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)”的简称. ASP.NET Boilerplate是一个用最佳实践和流行技术开发现代WEB应 ...
- 使用Jekyll在Github上搭建博客
最近在玩github,突然发现很多说明网站或者一些介绍页面全部在一个域名是*****.github.io上. 好奇!!!真的好奇!!!怎么弄的?我也要一个~~~ 于是去网站上查询了一下,找到了http ...
- Ext.NET-基础篇
概述 本文介绍Ext.NET的基本概念,安装配置.布局以及容器,最后介绍了DirectEvents.DirectMethod.Listener,并提供了示例代码. 示例代码下载地址>>&g ...
- java文件cmd运行出现中文乱码
今天刚开始学java,使用cmd命令执行java文件的时候,发现中文打出来是一串乱码. 于是就百度了一下,发现一个行之有效的方法. 首先使用命令:javac -encoding utf-8 Hello ...
- 35-less 简明笔记
分屏显示文本文件 less [options] [file-list] less与more类似,但比more更加完善 例如:在显示一屏文本之后,less将显示提示副等待下一条命令的输入;可以向前或向后 ...
- bitmap转化base64
/** * bitmap转化base64 */public static String bitmapToBase64(Bitmap bitmap) { String result = null; By ...
- Android EditText控件即设置最小高度又运行高度随内容增加而变化
(转)http://www.aichengxu.com/view/1405748 记录学习用 如题,有时候EditText需要一个最小的高度,但是在输入更多内容时,要随着内容的增加而变化高度,一般 ...