zoukankan      html  css  js  c++  java
  • CF988D Points and Powers of Two 数学结论题 规律 第十题

    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 |xijxik|=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 (1n21051≤n≤2⋅105) — the number of points.

    The second line contains nn pairwise distinct integers x1,x2,,xnx1,x2,…,xn (109xi109−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 |73|=4=22|7−3|=4=22, |75|=2=21|7−5|=2=21 and |35|=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满足题目的要求

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

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

    彼时当年少,莫负好时光。
  • 相关阅读:
    [转]让搜索跨越语言的鸿沟—谈跨语言信息检索技术
    【PRML读书笔记-Chapter1-Introduction】1.6 Information Theory
    【PRML读书笔记-Chapter1-Introduction】1.5 Decision Theory
    [科研小记]
    【PRML读书笔记-Chapter1-Introduction】1.4 The Curse of Dimensionality
    【Machine Learning】wekaの特征选择简介
    【PRML读书笔记-Chapter1-Introduction】1.3 Model Selection
    【迁移学习】2010-A Survey on Transfer Learning
    【Machine Learning】机器学习の特征
    【PRML读书笔记-Chapter1-Introduction】1.2 Probability Theory
  • 原文地址:https://www.cnblogs.com/l609929321/p/9220973.html
Copyright © 2011-2022 走看看