跳到正文

题解

[CF988D] Points and Powers of Two 题解

Oracynx约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月11日
篇幅
约 3 分钟
获赞
1
题目
CF988D

版本

  1. v1当前

[CF988D] Points and Powers of Two 题解

思路分析

显然,最多存在 33 个数,证明如下:

a<b<c<da+2i=b,b+2j=c∵c−a=2k,k∈Z∴i=j∴d=c+2i+1=a+2i+2∴¬l∈Z,d−b=2la < b < c < d \\ a + 2^i = b, b + 2^j = c \\ \because c - a = 2^k, k \in \mathbb{Z} \\ \therefore i = j \\ \therefore d = c + 2^{i + 1} = a + 2^{i + 2} \\ \therefore \neg l \in \mathbb{Z}, d - b = 2 ^ l \\

所以最多只能有 33 个数。

代码实现

C++
#include <cstdio>
#include <map>
constexpr int MaxN = 2e5 + 5;
int n;
long long p[MaxN];
std::map<long long, bool> map;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &p[i]);
        map[p[i]] = true;
    }
    for (int i = 1; i <= n; i++)
    {
        for (long long j = 1; j <= 2e9; j *= 2)
        {
            if (map.count(p[i] + j) && map.count(p[i] + 2 * j))
            {
                printf("3\n");
                printf("%lld %lld %lld\n", p[i], p[i] + j, p[i] + 2 * j);
                return 0;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (long long j = 1; j <= 2e9; j *= 2)
        {
            if (map.count(p[i] + j))
            {
                printf("2\n");
                printf("%lld %lld\n", p[i], p[i] + j);
                return 0;
            }
        }
    }
    printf("1\n");
    printf("%lld\n", p[1]);
    return 0;
}
原文