codeforces 702B B. Powers of Two(水题)
题目链接:
3 seconds
256 megabytes
standard input
standard output
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 xexists so that ai + aj = 2x).
The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
4
7 3 2 1
2
3
1 1 1
3 题意:
问有多少对a[i]+a[j]是2的次幂; 思路: map搞一搞; AC代码:
/************************************************
┆ ┏┓ ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃ ┃ ┆
┆┃ ━ ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃ ┃ ┆
┆┃ ┻ ┃ ┆
┆┗━┓ ┏━┛ ┆
┆ ┃ ┃ ┆
┆ ┃ ┗━━━┓ ┆
┆ ┃ AC代马 ┣┓┆
┆ ┃ ┏┛┆
┆ ┗┓┓┏━┳┓┏┛ ┆
┆ ┃┫┫ ┃┫┫ ┆
┆ ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=(1<<8);
const double eps=1e-8; int a[N],cnt=0,b[50]; map<int,int>mp,vis; inline void Init()
{
LL temp=2;
while(temp<=2e9+100)
{
b[++cnt]=(int)temp;
temp=temp*2;
}
}
int main()
{ Init();
int n;
read(n);
For(i,1,n)read(a[i]),mp[a[i]]++,vis[a[i]]=1;
LL ans=0;
For(i,1,n)
{
For(j,1,cnt)
{
if(vis[b[j]-a[i]])
{
int x=b[j]-a[i];
if(x==a[i])
{
ans=ans+mp[x]-1;
}
else
{
ans=ans+mp[x];
}
}
}
}
cout<<ans/2<<endl; return 0;
}
codeforces 702B B. Powers of Two(水题)的更多相关文章
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
- Codeforces 1082B Vova and Trophies 模拟,水题,坑 B
Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...
- CodeForces 686A Free Ice Cream (水题模拟)
题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...
随机推荐
- springboot多环境配置
springboot多环境(dev.test.prod)配置 2017-07-17 10:33 1290人阅读 评论(0) 收藏 举报 分类: spring boot(6) 版权声明:本文为博主原 ...
- CapIp.pas
unit CapIp; interface uses Windows, Messages,Classes,winsock,sysutils; const WM_CapIp = WM_USER + ; ...
- c++中.dll与.lib文件的生成与使用的详解
两种库: • 包含了函数所在的DLL文件和文件中函数位置的信息(入口),代码由运行时加载在进程空间中的DLL提供,称为动态链接库dynamic link library.• 包含函数代码本身,在编译时 ...
- C#使用CurrentUICulture切换语言
1. 创建2个窗口 2. 窗口1属性Localizable设置为True,Language选择英语(美国) 然后把窗口1中控件的Text由中文编辑成英文,Form2一样设置. 此时,Form1 ...
- 微信小程序制作商 业务流程
- Odoo calendar 提醒器
Odoo calendar 提供了一个提醒功能,它包含邮件通知以及web client弹窗功能 创建日历事件的时候,可以设置提醒器 Meeting [ calendar.event ] ...
- dubbo学习之Hello world
现在企业中使用dubbo的越来越多,今天就简单的学习一下dubbo,写了一个hello world,教程仅供入门,如要深入学习请上官网 服务提供方: 首先将提供方和消费方都引入jar包,如果使用的是m ...
- linux查找文件夹下的全部文件里是否含有某个字符串
查找文件夹下的全部文件里是否含有某个字符串 find .|xargs grep -ri "IBM" 查找文件夹下的全部文件里是否含有某个字符串,而且仅仅打印出文件名称 fin ...
- man screen
http://www.gnu.org/software/screen/manual/screen.html Screen User's Manual Next: Overview, Previous: ...
- python-pyDes-ECB加密-DES-DES3加密
网上的教程都他妹的是抄的,抄也就算了,还改抄错了,害我写了一两天都没找到原因,直接去官网看,找例子很方便 官网链接:http://twhiteman.netfirms.com/des.html 一个小 ...