CodeForces 702B Powers of Two
简单题。
开一个$map$记录一下每个数字出现了几次,那么读入的时候$f[a[i]]+1$。
计算$a[i]$做出的贡献的时候,先把$f[a[i]]-1$,然后再枚举$x$,答案加上$f[{2^x} - a[i]]$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
LL a[maxn],ans;
map<LL,int>f;
int n; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[i]),f[a[i]]++;
for(int i=;i<=n;i++)
{
f[a[i]]--; LL sum=;
for(int j=;j<=;j++)
{
ans=ans+f[sum-a[i]];
sum=sum*;
}
}
printf("%lld\n",ans);
return ;
}
CodeForces 702B Powers of Two的更多相关文章
- 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, ...
- CodeForces 702B Powers of Two (暴力,优化)
题意:给定 n 个数,问你从有多少下标 i < j,并且 ai + aj 是2的倍数. 析:方法一: 从输入开始暴力,因为 i < j 和 i > j 是一样,所以可以从前面就开始查 ...
- codeforces 702B B. Powers of Two(水题)
题目链接: B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- CF 702B Powers of Two(暴力)
题目链接: 传送门 Devu and Partitioning of the Array time limit per test:3 second memory limit per test: ...
- Codeforces 702B【二分】
题意: 给一个a数组,输出有多少对相加是等于2^x的.1<=a[i]<=1e9,n<=1e5 思路: a[i]+a[j]=2^x 对于每个a[i],枚举x,然后二分查找a[j]; p ...
- CodeForces 404C Ivan and Powers of Two
Ivan and Powers of Two Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & % ...
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces 622 F. The Sum of the k-th Powers
\(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i ...
- Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法
F. The Sum of the k-th Powers 题目连接: http://www.codeforces.com/contest/622/problem/F Description Ther ...
随机推荐
- [开发者账号] ios7苹果开发者账号申请
1.登陆 https://developer.apple.com/ 2.点击网站最底部的 3.点击 4.然后根据提示继续点击 注意:1.点击的过程中注意个人和企业账号 开发者类型等 2.付款账号的 ...
- java基础练习 8
public class Eighth { /*判断101-200之间有多少个素数,并输出所有素数.素数又叫质数,就是除了1和它本身之外,再也没有整数能被它整除的数.也就是素数只有两个因子.*/ pu ...
- SpringMVC 学习-上传文件分解器 CommonsMultipartResolver 类
Spring 组件 CommonsMultipartResolver 类的主要作用是配置文件上传的一些属性,也可以控制上传文件的大小. 在 springmvc-servlet.xml 配置文件中: & ...
- minSdkVersion与targetSdkVersion
targetSdkVersion是Android提供向前兼容的主要依据,在应用的targetSdkVersion没有更新之前,系统不会应用最新的行为变化 比如设置了app的targetSdkVersi ...
- PDF转换成Txt
我的弱智想法是所有能转换成PDF的文件,就都用PDF预览,上传成功后开启一个线程把文档转换成PDF,PDF再转换成txt. 目的是把txt插入索引进行全文检索. 调用的时候 string filePa ...
- solr最佳实践
管理页面 页面地址:http://{ip}:{port}/solr/#/ 管理页面的data-import页可以手动重建索引,configuration指定了数据源,重建索引也可以通过http请求触发 ...
- DOM学习笔记--入门1
HTML DOM 是关于如何获取.修改.添加或删除 HTML 元素的标准. 首先节点有很多种,不仅仅HTML元素是节点,尤其 要注意文本节点的存在. 根据 W3C 的 HTML DOM 标准,HTML ...
- DotNetZip 压缩下载
var fs = Response.OutputStream; using (ZipFile zip = new ZipFile(System.Text.Encoding.UTF8)) //编码是解决 ...
- 著名清理软件(CCleaner) 5.24.5841 中文版
软件名称: 著名清理软件(CCleaner) 软件语言: 多国语言 授权方式: 免费软件 运行环境: Win 32位/64位 软件大小: 5.7MB 图片预览: 软件简介: CCleaner的体积小, ...
- iOS缓存
存储缓存: 第三方应用只能把信息保存在应用程序的沙盒中.因为缓存数据不是用户产生的,所以它应该被保存在NSCachesDirectory,而不是NSDocumentsDirectory.为缓存数据创建 ...