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 ...
随机推荐
- office全系列激活脚本-改良版
@ECHO OFFTITLE office 全版本系统激活@echo offfor /l %%a in (8,1,16) do (for /f "tokens=*" %%i in ...
- 某大神C#框架后台发送信息的查找及破解
最近在博客园瞎逛的时候,发现了某个大神发布的一个c#框架,一看框架,叫牛逼框架,嗯,装B效果太好了,界面很炫,虽然有很多的组件还是不怎么完善,但是,已经可以初步运用于项目了. 先来看看界面: 在进 ...
- 结构-行为-样式-PS笔记
1.矩形选框,按住Shift就可以成为正圆或者正方形.按住ALt就可以控制圆心的位置: 2.美颜:滤镜--模糊--回到开始--历史记录工具,去掉不要的地方. 3.套索工具双击闭合:4.钢笔工具是做选区 ...
- C语言之总结1
1). 终端常用的命令: pwd 显示终端的工作路径. ls list 清单 显示当前工作路径下的所有的文件以及文件夹. ls -l 以详细信息显示当前工作路径下的所有的文件以及文件夹. cd 要切 ...
- Python print报ascii编码异常的靠谱解决办法
之前遇到此异常UnicodeEncodeError: 'ascii' codec can't encode characters...,都是用这种方式解决:sys.setdefaultencoding ...
- android浏览器 源码共享
浏览器源码共享 [天天浏览器]拥有极为精简的内核,手机App大小在2MB以内,是市场上极省用户手机内存,极少占用手机资源,速度极快的浏览器,本身功能完整强大,是极速上网必备的利器. 源代码下载地址:h ...
- 事件拦截,仿qq侧拉的操作中
1,处理DrawerLayout自定义的侧拉菜单时候,当手指点击listview的时候,不起作用,就是因为 手指滑动稍微有一点x方向的动作,抽屉控件就请求父控件(listview)不要拦截,这样lis ...
- 【USACO】接住苹果
接住苹果奶牛喜欢吃苹果.约翰有两棵苹果树,有 N 只苹果会从树上陆续落下.如果掉苹果的时候,贝西在那棵树下,她就能接住苹果.贝西一开始在第一棵树下.在苹果掉落之前,她有足够的时间来回走动,但她很懒,最 ...
- 实战ASP.NET访问共享文件夹(含详细操作步骤)
博客园找找看(http://zzk.cnblogs.com)的索引文件占用空间太大,需要移至另外一台服务器,所以要解决"在ASP.NET中通过共享文件夹访问索引文件"的问题. 假设 ...
- Unity启动事件-监听:InitializeOnLoad
[InitializeOnLoad] :在启动Unity的时候运行编辑器脚本 官方案例: using UnityEngine; using UnityEditor; [InitializeOnLoa ...