题目链接:

B. Powers of Two

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

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).

Input

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).

Output

Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.

Examples
input
  1. 4
    7 3 2 1
output
  1. 2
input
  1. 3
    1 1 1
output
  1. 3
  2.  
  3. 题意:
    问有多少对a[i]+a[j]是2的次幂;
  4.  
  5. 思路:
  6.  
  7. map搞一搞;
  8.  
  9. AC代码:
  1. /************************************************
  2. ┆ ┏┓   ┏┓ ┆
  3. ┆┏┛┻━━━┛┻┓ ┆
  4. ┆┃       ┃ ┆
  5. ┆┃   ━   ┃ ┆
  6. ┆┃ ┳┛ ┗┳ ┃ ┆
  7. ┆┃       ┃ ┆
  8. ┆┃   ┻   ┃ ┆
  9. ┆┗━┓   ┏━┛ ┆
  10. ┆  ┃   ┃  ┆      
  11. ┆  ┃   ┗━━━┓ ┆
  12. ┆  ┃  AC代马   ┣┓┆
  13. ┆  ┃    ┏┛┆
  14. ┆  ┗┓┓┏━┳┓┏┛ ┆
  15. ┆   ┃┫┫ ┃┫┫ ┆
  16. ┆   ┗┻┛ ┗┻┛ ┆
  17. ************************************************ */
  18.  
  19. #include <iostream>
  20. #include <cstdio>
  21. #include <cstring>
  22. #include <algorithm>
  23. #include <cmath>
  24. #include <bits/stdc++.h>
  25. #include <stack>
  26.  
  27. using namespace std;
  28.  
  29. #define For(i,j,n) for(int i=j;i<=n;i++)
  30. #define mst(ss,b) memset(ss,b,sizeof(ss));
  31.  
  32. typedef long long LL;
  33.  
  34. template<class T> void read(T&num) {
  35. char CH; bool F=false;
  36. for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
  37. for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
  38. F && (num=-num);
  39. }
  40. int stk[70], tp;
  41. template<class T> inline void print(T p) {
  42. if(!p) { puts("0"); return; }
  43. while(p) stk[++ tp] = p%10, p/=10;
  44. while(tp) putchar(stk[tp--] + '0');
  45. putchar('\n');
  46. }
  47.  
  48. const LL mod=1e9+7;
  49. const double PI=acos(-1.0);
  50. const int inf=1e9;
  51. const int N=1e5+10;
  52. const int maxn=(1<<8);
  53. const double eps=1e-8;
  54.  
  55. int a[N],cnt=0,b[50];
  56.  
  57. map<int,int>mp,vis;
  58.  
  59. inline void Init()
  60. {
  61. LL temp=2;
  62. while(temp<=2e9+100)
  63. {
  64. b[++cnt]=(int)temp;
  65. temp=temp*2;
  66. }
  67. }
  68. int main()
  69. { Init();
  70. int n;
  71. read(n);
  72. For(i,1,n)read(a[i]),mp[a[i]]++,vis[a[i]]=1;
  73. LL ans=0;
  74. For(i,1,n)
  75. {
  76. For(j,1,cnt)
  77. {
  78. if(vis[b[j]-a[i]])
  79. {
  80. int x=b[j]-a[i];
  81. if(x==a[i])
  82. {
  83. ans=ans+mp[x]-1;
  84. }
  85. else
  86. {
  87. ans=ans+mp[x];
  88. }
  89. }
  90. }
  91. }
  92. cout<<ans/2<<endl;
  93.  
  94. return 0;
  95. }

  

codeforces 702B B. Powers of Two(水题)的更多相关文章

  1. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  2. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  3. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  4. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  5. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  7. Codeforces - 1194B - Yet Another Crosses Problem - 水题

    https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...

  8. Codeforces 1082B Vova and Trophies 模拟,水题,坑 B

    Codeforces 1082B Vova and Trophies https://vjudge.net/problem/CodeForces-1082B 题目: Vova has won nn t ...

  9. CodeForces 686A Free Ice Cream (水题模拟)

    题意:给定初始数量的冰激凌,然后n个操作,如果是“+”,那么数量就会增加,如果是“-”,如果现有的数量大于等于要减的数量,那么就减掉,如果小于, 那么孩子就会离家.问你最后剩下多少冰激凌,和出走的孩子 ...

随机推荐

  1. 邁向IT專家成功之路的三十則鐵律 鐵律五:IT人穩定發展之道-去除惡習

    在我們努力邁向IT專家成功之路的過程當中,實際上會遭遇到許多障礙來影響我們前進,然而在這諸多障礙之中,最難克服的並非是旁人對我們所造成的影響,而是無形之間自己對自己所造的阻礙,如果沒有隨時隨地加以自反 ...

  2. 在Intellij上面导入项目 & AOP示例项目 & AspectJ学习 & Spring AoP学习

    为了学习这篇文章里面下载的代码:http://www.cnblogs.com/charlesblc/p/6083687.html 需要用Intellij导入一个已有工程.源文件原始内容也可见:link ...

  3. 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 【转】

    http://www.cnblogs.com/powertoolsteam/p/MVC_one.html 系列文章 七天学会ASP.NET MVC (一)——深入理解ASP.NET MVC 七天学会A ...

  4. Python基础语法03-控制流

    Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和 ...

  5. python3 查看已安装的模块

    一.命令行下使用pydoc命令 在命令行下运行$ pydoc modules即可查看 二.在python交互解释器中使用help()查看 在交互式解释器中输入>>> help(&qu ...

  6. xterm.js 基于websocket 链接容器 命令行工具

    <template> <div> <el-dialog title="命令" :visible.sync="dialogTableVisib ...

  7. Linux Kernel Maintainers

    http://en.wikipedia.org/wiki/Ingo_Molnár http://zh.wikipedia.org/wiki/英格·蒙內 Ingo Molnár Ingo Molnár, ...

  8. 实习日记 laravel怎么删除磁盘上的文件

    Storage 里面有 delete的方法 具体使用是 Storage::disk('uploads')->delete($fileName); 其中'uploads'是filesystem里面 ...

  9. svn 版本管理与自动部分发布(转)

    作为团队开发项目时,会遇到项目的版本管理,测试部署与发布部署,下面是摘至他人的关于版本管理和自动部署的方案. svn自动部署的实现: 使用svn的hook功能 1.在版本库的hooks目录下面,有一些 ...

  10. java对象访问

    下面这句代码: Object obj = new Object(); 对象引用在栈中,对象实体存在堆中,引用的方式有两种,分别是通过句柄访问对象和通过直接指针访问对象. Sun HotSpot使用第二 ...