CF988 D. Points and Powers of Two【hash/数学推理】
【链接】: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/数学推理】的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- CF988 C. Equal Sums【map+pair/hash/任选两个序列,两个序列都除去他们中的一个数,使的总和相同】
[链接]:CF988C [题意]:在n个序列中任选两个序列,两个序列都除去他们中的一个数,使的总和相同 [分析]:map<int,pair<int,int> > mp,从0~m ...
- 【Codeforces 988D】Points and Powers of Two
[链接] 我是链接,点我呀:) [题意] 让你从一个集合中找出来一个子集 使得这个子集中任意两个数相减的绝对值是2^的整数次幂 且集合的大小最大 [题解] 考虑子集的个数为4个或4个以上 那么我们找到 ...
- Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...
- Codeforces 988D Points and Powers of Two ( 思维 || 二的幂特点 )
题目链接 题意 : 给出坐标轴上的 n 个点的横坐标,要你选出最多的点,使得这些点两两距离是二的幂 ( 特殊情况 : 选出的集合只有一个点也满足条件 ) 分析 : 官方题解已经说的很好了 最关键是是判 ...
- hdu 5626 Clarke and points 数学推理
Clarke and points Problem Description The Manhattan Distance between point A(XA,YA) and B(XB,YB) i ...
- 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 ...
随机推荐
- Java学习全攻略-->阅读官方文档
一直感觉Java的官方文档有些杂乱,最近特意整理了一下,仅供参考. 入口 Oracle官方文档入口:http://docs.oracle.com/.下级页面这边只整理了JavaEE跟JavaSE的文档 ...
- JS设置cookie,读取cookie,删除cookie
总结了一下cookie的使用,不全面.都是基础的知识,后期还会再添加. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- Luogu 3435 POI2006OKR-Periods of Words(kmp)
显然答案应该是Σi-next[next[……next[i]]] (next[next[……next[i]]]>0).递推即可. #include<iostream> #include ...
- FFT多项式乘法模板
有时间来补算法原理orz #include <iostream> #include <cstdio> #include <cmath> #include <c ...
- Citrix Netscaler负载均衡算法
Citrix Netscaler负载均衡算法 http://blog.51cto.com/caojin/1926308 众所周知,作为新一代应用交付产品的Citrix Netscaler具有业内领先的 ...
- TextView AutoLink, ClikSpan 与长按事件冲突的解决
前言 首先,我们先来复习一下 autoLink 和 ClickableSpan 是干什么用的. autoLink 当中有五个属性值:分别是 phone.email.map.web.all 和 none ...
- [Leetcode] merge sorted array 合并数组
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
- [CERC2017]Intrinsic Interval——扫描线+转化思想+线段树
[CERC2017]Intrinsic Interval https://www.luogu.org/blog/ywycasm/solution-p4747# 这种“好的区间”,见得还是比较多的了. ...
- java md5加密 不依赖base64包
/** * MD5 加密 */ private String getMD5Str(String str) { MessageDigest messageDigest = null; try { mes ...
- Dokuwiki 二次开发记录
Dokuwiki 二次开发记录 [转]http://www.syyong.com/other/Dokuwiki-Secondary-Development-Record.html DokuWiki 是 ...