题目链接

题意 : 给出坐标轴上的 n 个点的横坐标,要你选出最多的点,使得这些点两两距离是二的幂 ( 特殊情况 : 选出的集合只有一个点也满足条件 )

分析 :

官方题解已经说的很好了

最关键是是判断选出的集合元素数量肯定不可能大于 3

简单翻译一下题解就是

假设现有答案集合元素数量为 4 ,且令其为 a、b、c、d ( a < b < c < d )

令 a、b 间距为 dist(a, b) = 2^k

令 b、c 间距为 dist(b, c) = 2^l

则可得出 dist(a, c) = dist(a, b) + dist(b, c) = 2^k + 2^l = 2^m

根据二的幂相加的性质,可以得出 k == l ( !!!!! 这个思想很重要 !!!!!! )

对于 a、b、c 有如上关系,所以对于 b、c、d 也有同样的关系

所以有 dist(a, b) = dist(b, c) = dist(c, d) = 2^k

故有 dist(a, d) = 3 * 2^k 这个因为有因子 3 的存在,所以定不是二的幂

故推出答案集元素数量为 4 是不可行的,由此可以推广出 大于 4 的也都不可行

所以只要枚举二的幂,然后对于每一个点去检查其加上或者减去当前枚举的二的幂的元素是否存在

若都存在,那么肯定存在答案集合大小为 3 的解。若只存在一个,则存在答案集合大小为 2 的解。

若枚举完了都没有的话,那么答案集合大小只能为 1 ,此时随便输出一个元素即可。

#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long

#define scs(i) scanf("%s", i)
#define sci(i) scanf("%d", &i)
#define scd(i) scanf("%lf", &i)
#define scl(i) scanf("%lld", &i)
#define scIl(i) scanf("%I64d", &i)
#define scii(i, j) scanf("%d %d", &i, &j)
#define scdd(i, j) scanf("%lf %lf", &i, &j)
#define scll(i, j) scanf("%lld %lld", &i, &j)
#define scIll(i, j) scanf("%I64d %I64d", &i, &j)
#define sciii(i, j, k) scanf("%d %d %d", &i, &j, &k)
#define scddd(i, j, k) scanf("%lf %lf %lf", &i, &j, &k)
#define sclll(i, j, k) scanf("%lld %lld %lld", &i, &j, &k)
#define scIlll(i, j, k) scanf("%I64d %I64d %I64d", &i, &j, &k)

#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define lowbit(i) (i & (-i))
#define mem(i, j) memset(i, j, sizeof(i))

#define fir first
#define sec second
#define ins(i) insert(i)
#define pb(i) push_back(i)
#define pii pair<int, int>
#define mk(i, j) make_pair(i, j)
#define all(i) i.begin(), i.end()
#define pll pair<long long, long long>

#define _TIME 0
#define _INPUT 0
#define _OUTPUT 0
clock_t START, END;
void __stTIME();
void __enTIME();
void __IOPUT();
using namespace std;
;
LL arr[maxn];

int main(void){__stTIME();__IOPUT();

    set<LL> s;
    int n;
    sci(n);

    ; i<=n; i++){
        scIl(arr[i]);
        s.ins(arr[i]);
    }

    LL ans1, ans2, ans3;
    bool _3 = false;
    bool _2 = false;
    ; i<=; i++){
        ; j<=n; j++){
            if(s.count(arr[j]+(1LL<<i))){
                if(!_2){
                    _2 = true;
                    ans1 = arr[j];
                    ans2 = arr[j]+(1LL<<i);
                }
                if(s.count(arr[j]-(1LL<<i))){
                    if(!_3){
                        _3 = true;
                        ans1 = arr[j]-(1LL<<i);
                        ans2 = arr[j];
                        ans3 = arr[j]+(1LL<<i);
                    }
                }
            }
            if(_3) break;
        }
        if(_3) break;
    }

    if(_3){
        puts(");
        return !printf("%I64d %I64d %I64d\n", ans1, ans2, ans3);
    }

    if(_2){
        puts(");
        return !printf("%I64d %I64d\n", ans1, ans2);
    }

    printf(]);

__enTIME();;}

void __stTIME()
{
    #if _TIME
        START = clock();
    #endif
}

void __enTIME()
{
    #if _TIME
        END = clock();
        cerr<<"execute time = "<<(double)(END-START)/CLOCKS_PER_SEC<<endl;
    #endif
}

void __IOPUT()
{
    #if _INPUT
        freopen("in.txt", "r", stdin);
    #endif
    #if _OUTPUT
        freopen("out.txt", "w", stdout);
    #endif
}

Codeforces 988D Points and Powers of Two ( 思维 || 二的幂特点 )的更多相关文章

  1. Codeforces Round #486 (Div. 3)988D. Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  2. CodeForces 577E Points on Plane(莫队思维题)

    题目描述 On a plane are nn points ( x_{i}xi​ , y_{i}yi​ ) with integer coordinates between 00 and 10^{6} ...

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

  4. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  5. CF988D Points and Powers of Two 数学结论题 规律 第十题

    Points and Powers of Two time limit per test 4 seconds memory limit per test 256 megabytes input sta ...

  6. 【Codeforces 988D】Points and Powers of Two

    [链接] 我是链接,点我呀:) [题意] 让你从一个集合中找出来一个子集 使得这个子集中任意两个数相减的绝对值是2^的整数次幂 且集合的大小最大 [题解] 考虑子集的个数为4个或4个以上 那么我们找到 ...

  7. CodeForces - 988D(思维STL)

    原文地址:https://blog.csdn.net/weixin_39453270/article/details/80548442 博主已经讲的很好了 题意: 从一个序列中,选出一个集合,使得集合 ...

  8. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  9. CodeForces 404C Ivan and Powers of Two

    Ivan and Powers of Two Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & % ...

随机推荐

  1. 【miscellaneous】星光级超低照度摄像机技术分析

    低照度摄像机采用了超灵敏度图像传感器和独有的电子倍增和噪点控制技术能够极大地提高摄像机的灵敏度,并且具备24小时全彩色实时效果,绝无普通低照度摄像机出现的拖尾现象,以满足对夜间高品质监控的需求.    ...

  2. Java学生成绩绩点管理系统

    一.考试要求: 1.按照测试内容要求完成程序的设计与编程: 2.建立学号姓名文件夹,如:“信 1805-1 班 20180001 XXX”,将源程序文件保存在文件夹中,压缩成 rar 文件提交. 3. ...

  3. MongoDB和Redis的区别

    1).内存管理机制 a.Redis的数据全部存储在内存当中,会定期写入到磁盘当中,当内存不够用时, 可以选择指定的LRU(最近最少使用算法)的算法删除数据: b.MongoDB数据存在内存,有Linu ...

  4. $NOI$ $2019$ 网络同步赛

    D2T1考试前测了自己造的“假”极限数据,看了看内存发现是118MB,感觉没问题就交上去了. 赛后用Lemon测了一下:MLE 88->0 对于别的题我已经不想再说什么了. update: 由于 ...

  5. 未能将文件 bin\zh-CHS\Webdiyer.MvcPager.resources.dll 复制到 obj\Release\Package\PackageTmp\bin\zh-CHS\Webdiyer.MvcPager.resources.dll。 未能找到文件“bin\zh-CHS\Webdiyer.MvcPager.resources.dll”

    在bin下面会生成更dll相同名称的xml文件,可能是因为我之前把项目中的很多部分设置了从项目中排除,关于dll也提示复制的问题解决办法是直接把那些生成的xml文件删除.在发布时还会提示obj文件夹下 ...

  6. java学习笔记(4)多态

    一.多态 --------------------------------------------- 1.定义:某一类事物的多种存在形态 例如:动物中猫,狗. 猫这个对象对应的类型是猫类型 猫 x  ...

  7. vue与angular 区别

    1.vue的双向数据绑定是基于 Es5中的getter和setter来实现的,而angular而是由自己实现的一套模板编译规则,需要进行 ‘脏’ 检查,vue则不需要,因此,vue性能上更高一些,但是 ...

  8. xcode中进行git代码管理

    http://www.cocoachina.com/ios/20140524/8536.html

  9. 2019-11-29-WPF-轻量级-MVVM-框架入门-2.1.2

    title author date CreateTime categories WPF 轻量级 MVVM 框架入门 2.1.2 lindexi 2019-11-29 10:16:10 +0800 20 ...

  10. shared_ptr的原理与应用

    new与赋值的坑 赋值(assignment)和new运算符在C++与Java(或C#)中的行为有本质的区别.在Java中,new是对象的构造,而赋值运算是引用的传递:而在C++中,赋值运算符意味着& ...