Summarize to the Power of Two
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai, there exists an element ajaj (i≠ji≠j) such that ai+ajai+aj is a power of two (that is, 2d2d for some non-negative integer dd).

For example, the following sequences are good:

  • [5,3,11][5,3,11] (for example, for a1=5a1=5 we can choose a2=3a2=3. Note that their sum is a power of two. Similarly, such an element can be found for a2a2 and a3a3),
  • [1,1,1,1023][1,1,1,1023],
  • [7,39,89,25,89][7,39,89,25,89],
  • [][].

Note that, by definition, an empty sequence (with a length of 00) is good.

For example, the following sequences are not good:

  • [16][16] (for a1=16a1=16, it is impossible to find another element ajaj such that their sum is a power of two),
  • [4,16][4,16] (for a1=4a1=4, it is impossible to find another element ajaj such that their sum is a power of two),
  • [1,3,2,8,8,8][1,3,2,8,8,8] (for a3=2a3=2, it is impossible to find another element ajaj such that their sum is a power of two).

You are given a sequence a1,a2,…,ana1,a2,…,an. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

Input

The first line contains the integer nn (1≤n≤1200001≤n≤120000) — the length of the given sequence.

The second line contains the sequence of integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all nn elements, make it empty, and thus get a good sequence.

Examples
input
  1. 6
    4 7 1 5 4 9
output
  1. 1
input
  1. 5
    1 2 3 4 5
output
  1. 2
input
  1. 1
    16
output
  1. 1
input
  1. 4
    1 1 1 1023
output
  1. 0
Note

In the first example, it is enough to delete one element a4=5a4=5. The remaining elements form the sequence [4,7,1,4,9][4,7,1,4,9], which is good.

题意:给你n个数,问去掉几个数后,每个数都被用上与另一个数和为2的幂数

分析:直接暴力枚举每个二的幂数减去当前数的差是否存在于这个数列中,用map存下每个数

  1. #include <map>
  2. #include <set>
  3. #include <stack>
  4. #include <cmath>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <string>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <algorithm>
  12. #define debug(a) cout << #a << " " << a << endl
  13. using namespace std;
  14. const int maxn = 2e5 + ;
  15. const int mod = 1e9 + ;
  16. typedef long long ll;
  17. ll a[maxn], vis[maxn];
  18. int main() {
  19. ll n;
  20. while( cin >> n ) {
  21. map<ll,ll> mm;
  22. for( ll i = ; i < n; i ++ ) {
  23. cin >> a[i];
  24. mm[a[i]] ++;
  25. }
  26. ll cnt = ;
  27. for( ll i = ; i < n; i ++ ) {
  28. bool flag = false;
  29. for( ll j = <<; j >= ; j /= ) {
  30. if( j > a[i] ) {
  31. if( ( a[i] == j/ && mm[j-a[i]] > ) || ( mm[j-a[i]] > && a[i] != j/ ) ) {
  32. flag = true;
  33. break;
  34. }
  35. }
  36. }
  37. if( !flag ) {
  38. //debug(a[i]), debug(i);
  39. cnt ++;
  40. }
  41. }
  42. cout << cnt << endl;
  43. }
  44. return ;
  45. }

CF1005C Summarize to the Power of Two 暴力 map的更多相关文章

  1. Summarize to the Power of Two(map+思维)

    A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai, there exists an element aj ...

  2. CF 1005C Summarize to the Power of Two 【hash/STL-map】

    A sequence a1,a2,-,an is called good if, for each element ai, there exists an element aj (i≠j) such ...

  3. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力

    D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of ...

  4. codeforces 633D D. Fibonacci-ish(dfs+暴力+map)

    D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...

  5. luoguP1555 尴尬的数字(暴力+map)

    题意 题解 枚举每一个可能的二进制数.扔到一个map里 再枚举每一个可能的三进制数看map有没有就行了 反正就是很水 #include<iostream> #include<cstr ...

  6. 当超强台风“山竹”即将冲进南海,Power BI 你怎么看?

    这个周末“山竹 ”强势来袭!很多人的目光都在关注暴力水果“山竹”,这个号称70年最强最大风力超17级 台风“山竹”今天就已经在小悦家窗台肆虐咆哮了一天了!不知其他的小伙伴们是不是好好的一个周末就只能被 ...

  7. 在Microsoft Power BI中创建地图的10种方法

    今天,我们来简单聊一聊“地图”. 在我们日常生活中,地图地位已经提升的越来越高,出门聚餐.驾驶.坐车.旅行......应运而生的就是各种Map APP. 作为数据分析师,我们今天不讲生活地图,要跟大家 ...

  8. hdu 3698 Let the light guide us(线段树优化&简单DP)

    Let the light guide us Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/O ...

  9. Codeforces Round #496 (Div. 3) ABCDE1

    //B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...

随机推荐

  1. 【nodejs原理&源码赏析(9)】用node-ssh实现轻量级自动化部署

    目录 一. 需求描述 二. 预备知识 IP+端口访问 域名访问 三. Nodejs应用的手动部署 四. 基于nodejs的自动部署 4.1 package.json中的scripts 4.2 自动化发 ...

  2. 7z 命令行方式生成自解压exe

    一.下载 7z是一个免费的工具,除了通过命令行的方式提供各种文件.压缩包相关的操作外,还提供了一种方式可以打出自解压的exe程序.该程序从运行到结束经历了三个流程: (1) 解压文件到用户临时目录: ...

  3. Android | Sqlite3

    Android 数据库创建及使用: 创建: package he3.sd.dao; import android.content.Context; import android.database.sq ...

  4. spring boot 加载自定义log4j 文件路径

    spring boot 使用log4j 打印时,需首先去除自带 Logger ,然后加入log4j 依赖 <dependencies> <!-- https://mvnreposit ...

  5. IOS7.0唯一“设备ID”的获取方法

    ios7.0 以后通过sysctl获得的mac地址已经失效,所有设备均为020000000000. 可以通过苹果的keychain机制,实现设备的唯一ID标示. 具体过程:在app第一次安装时,生成一 ...

  6. nodeJs跨域设置(express,koa2,eggJs)

    原生跨域 var http=require('http'); var server = http.createServer(function (req,res) { res.setHeader('Ac ...

  7. jQuery中的append中含有onClick的问题

    在jQuery中,当append中含有onClick时,点击事件无效果.需要在append完之后再额外绑定点击事件.

  8. 【0806 | Day 9】异常处理/基本的文件操作

    一.异常处理 异常即报错,可分为语法异常和逻辑异常 1. 语法异常 举个栗子 if #报错 syntaxerror 0 = 1 #报错 syntaxerror ... 正经地举个栗子 print(1) ...

  9. 1.1Django简介和虚拟环境配置

    MVC 大部分开发语言中都有MVC框架 MVC框架的核心思想是:解耦 降低各功能模块之间的耦合性,方便变更,更容易重构代码,最大程度上实现代码的重用 m表示model,主要用于对数据库层的封装 v表示 ...

  10. Oracle Job定时任务详解、跨数据库数据同步

    业务需求,需要与A公司做数据对接,我们公司用的Oracle,A公司用的SQL Server数据库,如何跨数据库建立连接呢?这里使用的是DBLink,不会配置的请看我的另外一篇博客:https://ww ...