Points and Powers of Two
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn distinct points on a coordinate line, the coordinate of ii-th point equals to xixi. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points xi1,xi2,…,ximxi1,xi2,…,xim such that for each pair xijxij, xikxik it is true that |xij−xik|=2d|xij−xik|=2d where dd is some non-negative integer number (not necessarily the same for each pair of points).

Input

The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of points.

The second line contains nn pairwise distinct integers x1,x2,…,xnx1,x2,…,xn (−109≤xi≤109−109≤xi≤109) — the coordinates of points.

Output

In the first line print mm — the maximum possible number of points in a subset that satisfies the conditions described above.

In the second line print mm integers — the coordinates of points in the subset you have chosen.

If there are multiple answers, print any of them.

Examples
input

Copy
6
3 5 4 7 10 12
output

Copy
3
7 3 5
input

Copy
5
-1 2 5 8 11
output

Copy
1
8
Note

In the first example the answer is [7,3,5][7,3,5]. Note, that |7−3|=4=22|7−3|=4=22, |7−5|=2=21|7−5|=2=21 and |3−5|=2=21|3−5|=2=21. You can't find a subset having more points satisfying the required property.

题意: 给你有n个数字的一个数列,问最多有多少个数字他们两两的差是2的幂次方数

首先我们来推导下题目的样例

假设有三个数a,b,c他们两两的差都是2的幂次方数

则有:

  b - a = 2^x; c - b = 2^y;

  由前面两个式子可以得到 c-a = 2^x + 2^y,而要使2^x+2^y等于一个2的幂次方数,当且仅当x=y

  而假设是四个数满足题意,则还可以列出一个式子d-c=2^z,结合前面的式子可以得到d-a=2^x+2^y+2^z;这样的式子右边的结果2^x+2^y+2^z是不可能等于一个2的幂次方数

综述一个数列中最多有三个数,他们两两的差是2的幂次方数

回到题目,我们现在来求最多几个数的差是2的幂次方数。我们只需要枚举三个数的情况就可以了。

而这样的三个数,肯定满足 a = b - 2^x , c = b + 2^x;由此我们知道只需要枚举每个数,看这个数减去和加上2^x的数是否存在于数列中。

由于每个数的最大值是10^9,所以我们枚举2的x次方时,最多枚举到31就可以了。这样我们程序的时间复杂度是2*10^5*31满足题目的要求

若存在就输出结束程序(或你的循环),若不存在,则记录下两个是否存在的情况(记录到了两个存在的情况也不要退出,覆盖前面的就好因为两个的后面可能会有三个的情况)

若最后没有两个的情况页没有三个的,则随便输出一个就好。

CF988D Points and Powers of Two 数学结论题 规律 第十题的更多相关文章

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

  2. [codevs5578][咸鱼]tarjan/结论题

    5578 咸鱼  时间限制: 1 s  空间限制: 128000 KB   题目描述 Description 在广袤的正方形土地上有n条水平的河流和m条垂直的河流,发达的咸鱼家族在m*n个河流交叉点都 ...

  3. BZOJ_1367_[Baltic2004]sequence_结论题+可并堆

    BZOJ_1367_[Baltic2004]sequence_结论题+可并堆 Description Input Output 一个整数R Sample Input 7 9 4 8 20 14 15 ...

  4. 享元模式 FlyWeight 结构型 设计模式(十五)

    享元模式(FlyWeight)  “享”取“共享”之意,“元”取“单元”之意. 意图 运用共享技术,有效的支持大量细粒度的对象. 意图解析 面向对象的程序设计中,一切皆是对象,这也就意味着系统的运行将 ...

  5. 代理模式 PROXY Surrogate 结构型 设计模式(十四)

    代理模式 PROXY 别名Surrogate 意图 为其他的对象提供一种代理以控制对这个对象的访问. 代理模式含义比较清晰,就是中间人,中介公司,经纪人... 在计算机程序中,代理就表示一个客户端不想 ...

  6. 桥接模式 桥梁模式 bridge 结构型 设计模式(十二)

      桥接模式Bridge   Bridge 意为桥梁,桥接模式的作用就像桥梁一样,用于把两件事物连接起来   意图 将抽象部分与他的实现部分进行分离,使得他们都可以独立的发展.  意图解析 依赖倒置原 ...

  7. [BZOJ3609][Heoi2014]人人尽说江南好 结论题

    Description 小 Z 是一个不折不扣的 ZRP(Zealot Round-game Player,回合制游戏狂热玩家), 最近他 想起了小时候在江南玩过的一个游戏.     在过去,人们是要 ...

  8. 【uoj#282】长度测量鸡 结论题

    题目描述 给出一个长度为 $\frac{n(n+1)}2$ 的直尺,要在 $0$ 和 $\frac{n(n+1)}2$ 之间选择 $n-1$ 个刻度,使得 $1\sim \frac{n(n+1)}2$ ...

  9. 【uoj#175】新年的网警 结论题+Hash

    题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...

随机推荐

  1. How to check all timestamps of a file

    A friend of mine she asked me how to check all timestamps of a file on an NTFS volume. She did not h ...

  2. Socket编程:UDP和TCP概论及案例

    网络编程的三要素: 1.IP地址  2.端口 3.协议 什么是Socket? Socket就是通信链路的端点称"套接词". 基于TCP协议的Socket网络通信: 用来实现双向安全 ...

  3. 封装 Gson 解析Json到对象是否失败

    在使用Google的 Gson 类库解析 Json 数据时,难免会出现解析失败的情况. 在这种情况下,使用 if(obj == null) 是不可行的,fromJson 方法会自动生成对象的实例,所以 ...

  4. Cobbler 自动安装CentOS7

    1. Cobbler介绍 Cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装.重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等.Cobbler可以使用命 ...

  5. 【C++】string::substr函数

    形式:s.substr(p, n) 返回一个string,包含字符串s中从p开始的n个字符的拷贝(p的默认值是0,n的默认值是s.size() - p,即不加参数会默认拷贝整个s) int main( ...

  6. 时间格式的字符串在ios中的转换问题

    在移动端使用时间选择器的时候,选择了一个时间转换为时间戳,谷歌浏览器以及安卓手机使用  new Date( 选择的时间 ).getTime()  都能够拿到时间戳, 但是在ios手机上会出现出现NAN ...

  7. Javascript中,实现十大排序方法之一(冒泡排序及其优化设想)

    冒泡排序的Javascript实现 首先定义一个取值范围在(0~100000)之间的随机值的长度为10万的数组, function bubbleSort(arr) { console.time('冒泡 ...

  8. Tomcat 方式部署 Solo 博客系统总结

      此篇为Tomcat部署方式,另有Docker部署方式,请参考文章<Docker 方式部署 Solo 博客系统总结> 一.环境和文件准备 服务器:购买的阿里云服务器,系统为Linux(C ...

  9. Python模块之pysnooper

    一.简介 调试程序时,很多人喜欢直接用print来代替断点调试,而pysnooper模块比print更方便,以装饰器的形式存在 二.实验环境 操作系统:win10 python版本:python3.6 ...

  10. MySQL--单表查询、多表查询简单概述

    表的前期准备: create table emp( id int not null unique auto_increment, name ) not null, sex enum('male','f ...