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/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的更多相关文章
- Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是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 ...
- Codeforces Round #486 (Div. 3) E. Divisibility by 25
Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #486 (Div. 3) A. Diverse Team
Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Des ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #245 (Div. 2) A - Points and Segments (easy)
水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
随机推荐
- JavaWeb——java.lang.UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: Native Library sqlite-3.8.6-amd64-sqlitejdbc.dll already loaded in a ...
- Python高级技巧:用一行代码减少一半内存占用
我想与大家分享一些我和我的团队在一个项目中经历的一些问题.在这个项目中,我们必须要存储和处理一个相当大的动态列表.测试人员在测试过程中,抱怨内存不足.下面介绍一个简单的方法,通过添加一行代码来解决这个 ...
- BZOJ 4872 luogu P3750 [六省联考2017]分手是祝愿
4872: [Shoi2017]分手是祝愿 Time Limit: 20 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description ...
- Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图
VectorDrawable 矢量图 三部曲: Android 开发 VectorDrawable 矢量图 (一)了解Android矢量图与获取矢量图 Android 开发 VectorDrawabl ...
- android 开发 View _7_ 动态自定义View
效果图: 代码: package com.example.lenovo.mydemo.myViewDemo; import android.content.Context; import androi ...
- 怎样让scrollview滚动到底部?
- (void)scrollsToBottomAnimated:(BOOL)animated { CGFloat offset = self.tableView.contentSize.height ...
- sql server driver ODBC驱动超时
- js day01
一)什么是JavaScript[以下简称JS] JS是 (1)基于对象 JS本身就有一些现成的对象可供程序员使用,例如:Array,Math,String... JS并不排除你可以自已按一定的规则创建 ...
- leetcode76
class Solution: def minWindow(self, s: str, t: str) -> str: n = len(s) if n==0: return "&quo ...
- leetcode104
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...