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 ...
随机推荐
- Putty的注册表设置
Putty是一款非常好用的远程管理Linux系统的工具,其主要具有以下几个优点: 完全免费; 在Windows 9x/NT/2000下运行的都非常好; 全面支持SSH1和SSH2: 绿色软件, ...
- Python反射函数
python里面跟getattr相关的有hasattr,setattr,delattr ,那么我们通过下面的例子,来详细的说说他们的用法. class Xiaorui: def __init__(s ...
- createElement、createTextNode、setAttribute使用方法
createElement() 方法可创建元素节点. 示例:var placeholder = document.createElement("img"); createTextN ...
- java 基本数据类型跟封装类型的差距
import java.util.*; class test1{ public static void main(String[] args){ long start1 = System.curren ...
- 给RelativeLayout设置背景,无效果bug解决
drawable文件夹下面 tomyshop_selector.xml文件 <?xml version="1.0" encoding="utf-8"?&g ...
- CodeForces 706E Working routine
十字链表. 开一个十字链表,矩阵中每一格作为一个节点,记录五个量: $s[i].L$:$i$节点左边的节点编号 $s[i].R$:$i$节点右边的节点编号 $s[i].U$:$i$节点上面的节点编号 ...
- Django- 'WSGIRequest' object has no attribute 'user'
在用django建第一个blog的时候,进入localhost:8000/admin的时候报上面的错: 查了好多资料,最后还是没解决,最后发现原因是我第一次建这个blog工程的时候用的django的版 ...
- .net core 11
- HTC与英特尔联手打造无线VR解决方案
除了TPCAST无线附件组件之外,HTC早前还宣布了与英特尔合作研发WiGig无线VR解决方案,他们还愿意寻找更多的合作伙伴以带来进一步的解决方案. HTC希望确保其Vive头显可以实现无线升级,让用 ...
- Java 并发 线程的生命周期
Java 并发 线程的生命周期 @author ixenos 线程的生命周期 线程状态: a) New 新建 b) Runnable 可运行 c) Running 运行 (调用 ...