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 IO 之 File 的创建、重命名与遍历
File表示存储设备上的一个文件或目录,使用方式查看API即可,比较简单 package org.zln.io.file; import java.io.File; /** * Created by ...
- 建议 里面的sql查找单列 外面的sql查找所有列 这样方便查找数据
- [BZOJ 2438] [中山市选2011]杀人游戏 Tarjan缩点
这个题很容易想到正解就是缩点找入度为零的点,那么我们考虑一种特殊情况就是,一个入度为零的点我们不访问他就知道他是不是凶手,那么这样的话就是:I. 他是一个真·孤立的点 II. 他在图里但是在他的强联通 ...
- bzoj 4880 [Lydsy1705月赛]排名的战争 贪心
[Lydsy1705月赛]排名的战争 Time Limit: 8 Sec Memory Limit: 256 MBSubmit: 338 Solved: 69[Submit][Status][Di ...
- 前端面试:提升web性能
1,减少HTTP请求数 A,从设计实现层简化页面 B,合理设置HTTP缓存 C,资源合并与压缩.如果可以的话,尽可能的将外部脚本,央视进行合并,多个合为一,css,javascript,image都可 ...
- 编写一个 Chrome 浏览器扩展程序
浏览器扩展允许我们编写程序来实现对浏览器元素(书签.导航等)以及对网页元素的交互, 甚至从 web 服务器获取数据,以 Chrome 浏览器扩展为例,扩展文件包括: 一个manifest文件(主文件, ...
- lesson 1
1.当前只是开始接触,安装并开始熟悉Visual Studio 的操作界面及基本设置 2.学习了新建项目,简单的hello world,及对颜色的更改.
- idea讲web项目部署到tomcat,热部署
idea是自动保存文件的,不需要ctrl+s手动保存. idea使用不习惯,修改了jsp文件后,刷新浏览器并没有立刻显示出来,而是要重新编译一下代码,重新部署才会出现. 在idea tomcat 中s ...
- eclipse更改web项目的WebContent目录
在使用eclipse 中 , 相信大家比我更是轻车熟路了 ( 我平常一般用 Intellij idea 的 ), 下面讲解一下在eclipse web项目中 , 如何设置 webroot 目录指向问题 ...
- AtCoder Regular Contest 082 F
Problem Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contai ...