【链接】 我是链接,点我呀:)

【题意】

让你从一个集合中找出来一个子集
使得这个子集中任意两个数相减的绝对值是2^的整数次幂
且集合的大小最大

【题解】

考虑子集的个数为4个或4个以上
那么我们找到最小的4个a[1],a[2],a[3],a[4]
显然
dis(1,2)=2^a
dis(2,3)=2^b
dis(1,3)=dis(1,2)+dis(2,3) = 2^c
因为2^a+2^b=2^c
所以可以推出来a=b
也即dis(1,2)=dis(2,3)
同理对于a[2],a[3],a[4]
用同样的方法可以得到
dis(2,3)=dis(3,4)
那么dis(1,4)=dis(1,2)*3=2^x*3
显然不是2的整数幂
因此不存在大小大于等于4的集合满足题意。
所以只要考虑集合大小为3以及为2的了
大小为3的话,只要枚举中间那个数字,根据上面的推论dis(1,2)=dis(2,3)
则枚举2^j
看看x-2^j和x+2^j是否存在就好
大小为2就更简单啦
大小为1就随便输出一个数字就好

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)2e5;
static class Task{ int n;
int x[] = new int[N+10];
TreeMap<Integer,Integer> dic = new TreeMap<Integer,Integer>(); public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();
for (int i = 1;i <= n;i++) {
x[i] = in.nextInt();
dic.put(x[i], 1);
}
for (int x:dic.keySet()) {
int cur = 1;
for (int j = 0;j <= 30;j++) {
int xl = x - cur,xr = x + cur;
if (dic.containsKey(xl) && dic.containsKey(xr)) {
out.println(3);
out.print(xl+" "+x+" "+xr);
return;
}
cur = cur * 2;
}
}
for (int x:dic.keySet()) {
int cur = 1;
for (int j = 0;j <= 30;j++) {
int xr = x + cur;
if (dic.containsKey(xr)) {
out.println(2);
out.print(x+" "+xr);
return;
}
cur = cur * 2;
}
} out.println(1);
out.println(x[1]);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 988D】Points and Powers of Two的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【51.27%】【codeforces 604A】Uncowed Forces

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【25.33%】【codeforces 552D】Vanya and Triangles

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  7. 【26.09%】【codeforces 579C】A Problem about Polyline

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 761B】Dasha and friends

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. 【转载】批量部署系统之kickstart

    一.安装各服务: ftp服务提供软件软件源,tftp提供引导文件,dhcp提供PXE文件位置,syslinux提供PXE文件 [root@node1~]# yum -y installtftp-ser ...

  2. git回到没push的commit

    创建: 2017/10/28   merge master以后数据库出了问题,改好以后发现view有点问题,commit以后没提交就reset了.过后才想起来怎么回去???吓成狗,索性找到了下面这个. ...

  3. bzoj 1572: [Usaco2009 Open]工作安排Job【贪心+堆】

    先按照时间顺序加,价值塞进小根堆里,碰到不合法情况就从堆里减去 #include<iostream> #include<cstdio> #include<queue> ...

  4. iOS 关于文件操作 NSFileManager

    创建文件夹 + (BOOL)creatDir:(NSString *)path { if (path.length==0) { return NO; } NSFileManager *fileMana ...

  5. git 详细部署及其应用

    第1章 版本控制系统 自动生成备份.随时回滚.知道改动的地方. 1.1 svn和git的区别 1.1.1 svn 集中式的版本控制系统,只有一个中央数据仓库,如果中央数据库仓库挂了或者不可访问,所有的 ...

  6. ASP.Net 知识点总结(四)

    1.get和post 的区别 get是从服务器上获取数据,post是向服务器传送数据; get安全性非常低,数据显示在地址栏,post安全性较高: 但是执行效率却比Post方法好: get有字节限制为 ...

  7. 403 Frog Jump 青蛙过河

    一只青蛙想要过河. 假定河流被等分为 x 个单元格,并且在每一个单元格内都有可能放有一石子(也有可能没有). 青蛙可以跳上石头,但是不可以跳入水中.给定石子的位置列表(用单元格序号升序表示), 请判定 ...

  8. RabbitMQ指南之五:主题交换器(Topic Exchange)

    在上一章中,我们完善了我们的日志系统,用direct交换器替换了fanout交换器,使得我们可以有选择性地接收消息.尽管如此,仍然还有限制:不能基于多个标准进行路由.在我们的日志系统中,我们可能不仅希 ...

  9. HTML5 页面调用微信接口

    参考微信微信官方文档JS_SDK:https://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#JSSDK.E4.BD.B ...

  10. js中时钟表盘

    1.js时钟表盘 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...