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

题目连接:

http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/D

Description

There are n distinct points on a coordinate line, the coordinate of i-th point equals to xi. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.

In other words, you have to choose the maximum possible number of points xi1,xi2,…,xim such that for each pair xij, xik it is true that |xij−xik|=2d where d is some non-negative integer number (not necessarily the same for each pair of points)

Sample Input

6
3 5 4 7 10 12

Sample Output

3
7 3 5

题意

给定一个集合,求最大子集,该子集内所有元素差都等于2的幂次。

题解:

假设a-b=2k,a-c=2i,i!=k时,b-c的值必不满足条件,所以最大子集最多只有三个元素

代码

#include <bits/stdc++.h>

using namespace std;

int n;
set<long long> s;
int ans;
vector<long long> v; int main() {
cin >> n;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
s.insert(x);
}
for (auto i:s) {
for (int o = 0; o < 33; o++) {
int flag1 = s.count(i - (1 << o));
int flag2 = s.count(i + (1 << o));
if (flag1 && flag2) {
cout << 3 << endl << (i - (1 << o)) << " " << i << " " << (i + (1 << o)) << endl;
return 0;
}
else if (flag1) {
if (!v.size()) {
v.push_back(i);
v.push_back(i - (1 << o));
}
}
else if (flag2) {
if (!v.size()) {
v.push_back(i);
v.push_back(i + (1 << o));
}
}
}
}
if (v.size()) {
cout << 2 << endl;
for (auto i: v) cout << i << " ";
}
else cout << 1 << endl << *s.begin();
}

Codeforces Round #486 (Div. 3) D. 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 Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round #486 (Div. 3) E. Divisibility by 25

    Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round #486 (Div. 3) A. Diverse Team

    Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...

  5. Codeforces Round #466 (Div. 2) -A. Points on the line

    2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 s ...

  6. Codeforces Round #319 (Div. 1) C. Points on Plane 分块

    C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...

  7. Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心

    A. Points and Segments (easy) Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  8. Codeforces Round #466 (Div. 2) A. Points on the line[数轴上有n个点,问最少去掉多少个点才能使剩下的点的最大距离为不超过k。]

    A. Points on the line time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #245 (Div. 2) A - Points and Segments (easy)

    水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

随机推荐

  1. java泛型的作用及实现原理

    一.泛型的介绍 泛型是Java 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Ja ...

  2. windows清空电脑的DNS缓存

    清空电脑的DNS缓存 按"Win+R"系统热键打开"运行"窗口,进入terminal终端 输入"ipconfig /flushdns"命令后 ...

  3. JDK1.7 ConcurrentHashMap--解决高并发下的HashMap使用问题

    高并发下也可以使用HashTable .Collections.synchronizedMap因为他们是线程安全的,但是却牺牲了性能,无论是读操作.写操作都是给整个集合加锁,导致同一时间内其他操作均为 ...

  4. input 选择框改变背景小技巧

    最近在项目中遇到一个问题,想要改变input选择框的背景,然而,令我没有想到的是,竟然无法直接改变背景的颜色 通常情况下:我们都可以通过改变元素的 background-color 的值来改变元素的背 ...

  5. 【转】vMAN 和 PVID

    vMAN关的情况下,如果用户的包内带有VLAN TAG,则以用户的TAG为准,如果用户的包内不带VLAN TAG,就打上PVID:vMAN开的情况下,无论用户的包内是否带有VLAN TAG,都强制在外 ...

  6. LAMP架构

    LAMP(linux,apache,mysql,php)是linux系统下常用的网站架构模型,用来运行PHP网站.(这得apache是httpd服务),这些服务可以安装同意主机上,也可以安装不同主机上 ...

  7. JAVA条件判断

    一.基本if结构 1.流程图 l  输入输出 l  判断和分支 l  流程线 1.1              简单的if条件判断 if(表达式){            //表达式为true,执行{ ...

  8. office 安装

    在 gaobo百度云下载安装包. 自定义安装,并在自定义界面选择安装路径. 破解:

  9. Selenium Java关闭浏览器

    在学习selenium的过程中发现一个问题,各种博客/教程都是教人用selenium的quit()和close()方法关闭浏览器. 但这不是我要的结果.这两个方法的前提是,用webdriver打开浏览 ...

  10. idea编辑项目出现【Information:java: javacTask: 源发行版 7 需要目标发行版 1.7】

    在编译项目时候出现问题: Information:java: javacTask: 源发行版 7 需要目标发行版 1.7 解决方案:按着图片操作,这几个地方设置的一样就可以了