【链接】:CF

【题意】:从一堆数中选一个最大子集,使得任意两个数相减的绝对值都是2的幂。

【分析】:首先很难的一点,需要想到子集最多只能有三个,四个及以上的子集一定不存在(可以证明)。当有三个元素时,则必有其中两对元素之差相等。

【代码】:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2*1e5+5;
const ll INF = 2147483647;
typedef pair<ll ,int> pli; ll n;
ll a[maxn]; int main()
{
set<ll> st;
scanf("%lld",&n);
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
st.insert(a[i]);
}
for(int i=0;i<n;i++)
{
for(ll t=1;t<1e18;t*=2)
{
if(st.count(a[i]+t) && st.count(a[i]+2*t))
{
printf("3\n");
printf("%lld %lld %lld\n",a[i],a[i]+t,a[i]+2*t);
return 0;
}
}
}
for(int i=0;i<n;i++)
{
for(ll t=1;t<1e18;t*=2)
{
if(st.count(a[i]+t))
{
printf("2\n");
printf("%lld %lld\n",a[i],a[i]+t);
return 0;
}
}
}
printf("1\n");
printf("%lld\n",a[0]);
}
/*
6
3 5 4 7 10 12 3
7 3 5 5
-1 2 5 8 11 1
8
*/

CF988 D. Points and Powers of Two【hash/数学推理】的更多相关文章

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

  3. Max Points on a Line (HASH TABLE

    QUESTIONGiven n points on a 2D plane, find the maximum number of points that lie on the same straigh ...

  4. CF988 C. Equal Sums【map+pair/hash/任选两个序列,两个序列都除去他们中的一个数,使的总和相同】

    [链接]:CF988C [题意]:在n个序列中任选两个序列,两个序列都除去他们中的一个数,使的总和相同 [分析]:map<int,pair<int,int> > mp,从0~m ...

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

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

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

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

  7. Codeforces 988D Points and Powers of Two ( 思维 || 二的幂特点 )

    题目链接 题意 : 给出坐标轴上的 n 个点的横坐标,要你选出最多的点,使得这些点两两距离是二的幂 ( 特殊情况 : 选出的集合只有一个点也满足条件 ) 分析 : 官方题解已经说的很好了 最关键是是判 ...

  8. hdu 5626 Clarke and points 数学推理

    Clarke and points Problem Description   The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...

  9. CF 305C ——Ivan and Powers of Two——————【数学】

    Ivan and Powers of Two time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. Java IO 之 FileFilter与FilenameFilter

    FileFilter与FilenameFilter可以实现对文件的过滤,他们都是接口,具体的过滤规则需要我们自己编写 1.FileFilter package org.zln.io.file; imp ...

  2. Param指南

    param name标签是在这个播放插件中嵌入的一些功能和播放参数: <param name="playcount" value="1"><! ...

  3. 关于IE缓存

    为了提高访问网页的速度,Internet Explorer浏览器会采用累积式加速的方法,将你曾经访问的网页内容(包括图片以及cookie文件等)存放在电脑里.这个存放空间,我们就称它为IE缓存.以后我 ...

  4. hdu 2199 Can you solve this equation? (二分法)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  5. AGC016C +/- Rectangle(构造)

    题目大意:给定H,W,h,w四个数,求是否满足矩阵的全部数之和和正数,h行w列之和为负数 如果h和w恰好是H,W的约数,则肯定不存在 否则肯定存在 只需要把h,w内每个元素填的足够大,然后小矩形的最后 ...

  6. Win10间歇性卡顿

    Win10间歇性卡顿 1.关闭不必要的服务:Windows Update.Windows Search.SuperFetch.Background Intelligent Transfer Servi ...

  7. BZOJ3132 上帝造题的七分钟 【二维树状数组】

    题目 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a,b),右下角为(c,d)的一个矩形区域内的全部数字加上一个值的 ...

  8. BZOJ 3545 / 洛谷 P4197 Peaks 解题报告

    P4197 Peaks 题目描述 在\(\text{Bytemountains}\)有\(N\)座山峰,每座山峰有他的高度\(h_i\).有些山峰之间有双向道路相连,共\(M\)条路径,每条路径有一个 ...

  9. CDQZ 2017 游记

    Day0: 提前放了一整天假,颓过去了.老吕让我去给B层的讲课,ppt还没做,只能在飞机上赶了QAQ.然后从上午到了衡水就一直在路上或者天上,到了晚上才到学校,然而ppt还是没有做完.还有,鄂尔多斯真 ...

  10. Spring中Resource接口的前缀书写格式

    Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt");   //这个 ...