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个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...
随机推荐
- 邁向IT專家成功之路的三十則鐵律 鐵律五:IT人穩定發展之道-去除惡習
在我們努力邁向IT專家成功之路的過程當中,實際上會遭遇到許多障礙來影響我們前進,然而在這諸多障礙之中,最難克服的並非是旁人對我們所造成的影響,而是無形之間自己對自己所造的阻礙,如果沒有隨時隨地加以自反 ...
- 在Intellij上面导入项目 & AOP示例项目 & AspectJ学习 & Spring AoP学习
为了学习这篇文章里面下载的代码:http://www.cnblogs.com/charlesblc/p/6083687.html 需要用Intellij导入一个已有工程.源文件原始内容也可见:link ...
- 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 【转】
http://www.cnblogs.com/powertoolsteam/p/MVC_one.html 系列文章 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 七天学会A ...
- Python基础语法03-控制流
Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和 ...
- python3 查看已安装的模块
一.命令行下使用pydoc命令 在命令行下运行$ pydoc modules即可查看 二.在python交互解释器中使用help()查看 在交互式解释器中输入>>> help(&qu ...
- xterm.js 基于websocket 链接容器 命令行工具
<template> <div> <el-dialog title="命令" :visible.sync="dialogTableVisib ...
- Linux Kernel Maintainers
http://en.wikipedia.org/wiki/Ingo_Molnár http://zh.wikipedia.org/wiki/英格·蒙內 Ingo Molnár Ingo Molnár, ...
- 实习日记 laravel怎么删除磁盘上的文件
Storage 里面有 delete的方法 具体使用是 Storage::disk('uploads')->delete($fileName); 其中'uploads'是filesystem里面 ...
- svn 版本管理与自动部分发布(转)
作为团队开发项目时,会遇到项目的版本管理,测试部署与发布部署,下面是摘至他人的关于版本管理和自动部署的方案. svn自动部署的实现: 使用svn的hook功能 1.在版本库的hooks目录下面,有一些 ...
- java对象访问
下面这句代码: Object obj = new Object(); 对象引用在栈中,对象实体存在堆中,引用的方式有两种,分别是通过句柄访问对象和通过直接指针访问对象. Sun HotSpot使用第二 ...