传送门:http://codeforces.com/contest/988/problem/D

题意:

在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次。

思路:

 可以知道最多有三个,差值为2、4;或者是a[i],a[i]+2的k次,a[i]-2的k次;

  两个就直接找。

  一个随便输出一个。

ac代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull; /*-----------------show time----------------*/
const int maxn = 2e5+;
int n;
ll a[maxn];
map<ll,int>mp;
ll ksm (int a,int b)
{
ll res = 1ll;
while(b)
{
if(b&)res = res * a;
a = a*a;
b>>=;
}
return res;
}
int main(){
scanf("%d", &n);
// cout<<ksm(2,1)<<endl;
for(int i=; i<=n; i++)
{
scanf("%lld" , &a[i]);
if(!mp.count(a[i]))mp[a[i]] = ;
mp[a[i]]++;
}
int flag2 = ,flag1 = ;
ll ans,jie;
for(int i=; i<=n&&flag1==; i++)
{
if(mp.count(a[i] + )&&mp.count(a[i]+))
{
flag2 = ;
ans = a[i];
break;
}
for(int j=; j<; j++)
{
if(mp.count(a[i]+ksm(,j))&&mp.count(a[i]-ksm(,j)))
{
ans = a[i];
jie = j;
flag1 = ;
break;
}
}
}
if(flag2)
{
printf("3\n%lld %lld %lld\n",ans,ans+,ans+);
return ;
}
if(flag1)
{
printf("3\n%lld %lld %lld\n",ans,ans+ksm(,jie),ans-ksm(,jie));
return ;
}
for(int i=; i<=n && flag2 == ; i++)
{
for(int j=; j<; j++)
{
if(mp.count(a[i]+ksm(,j)))
{
ans = a[i];
jie = j;
flag2 = ;
break;
}
}
}
if(flag2)
{
printf("2\n%lld %lld\n",ans,ans+ksm(,jie));
return ;
}
printf("1\n%lld\n",a[]); }

CF988D

Codeforces Round #486 (Div. 3)988D. Points and Powers of Two的更多相关文章

  1. 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 ...

  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. 【Intellij】Hot Swap Failed & class reloaded

    用 Intellij IDEA 编译程序时遇到了这个问题,如下图所示: 对结果貌似没什么影响,但暂时没找到出现这个情况的原因……

  2. Js面向对象构造函数继承

    构造函数继承 <!-- 创建构造函数 --> function Animal(){ this.species= '动物'; } function Dog(name,color){ this ...

  3. .NET Core CSharp 中级篇 2-2 List,ArrayList和Dictionary

    .NET Core CSharp 中级篇 2-2 本节内容为List,ArrayList,和Dictionary 简介 在此前的文章中我们学习了数组的使用,但是数组有一个很大的问题就是存储空间不足,我 ...

  4. Python实现网络多人聊天室

    网络多人聊天室 文件结构: chatroom ├── client.py  # 客户端代码 ├── language.py  # 语言文件 ├── server.py  # 服务端代码 └── set ...

  5. NLP(十三)中文分词工具的使用尝试

      本文将对三种中文分词工具进行使用尝试,这三种工具分别为哈工大的LTP,结巴分词以及北大的pkuseg.   首先我们先准备好环境,即需要安装三个模块:pyltp, jieba, pkuseg以及L ...

  6. 异步编程CompletableFuture实现高并发系统优化之请求合并

    先说场景: 根据Redis官网介绍,单机版Redis的读写性能是12万/秒,批量处理可以达到70万/秒.不管是缓存或者是数据库,都有批量处理的功能.当我们的系统达到瓶颈的时候,我们考虑充分的压榨缓存和 ...

  7. C程序设计(第四版)课后习题完整版 谭浩强编著

    //复习过程中,纯手打,持续更新,觉得好就点个赞吧. 第一章:程序设计和C语言 习题 1.什么是程序?什么是程序设计? 答:程序就是一组计算机能识别和执行的指令.程序设计是指从确定任务到得到结果,写出 ...

  8. koa2基于stream(流)进行文件上传和下载

    阅读目录 一:上传文件(包括单个文件或多个文件上传) 二:下载文件 回到顶部 一:上传文件(包括单个文件或多个文件上传) 在之前一篇文章,我们了解到nodejs中的流的概念,也了解到了使用流的优点,具 ...

  9. SVG和canvas渲染的性能比较

    1.什么是SVG? 描述: 一种使用XML描述的2D图形的语言 SVG基于XML意味着,SVG DOM中的每个元素都是可用的,可以为某个元素附加Javascript事件处理器. 在 SVG 中,每个被 ...

  10. 如何搭建环境---初识mybatis

    一:mybatis概念1:简介       MyBatis本是apache的一个开源项目iBatis,2010年改名为 MyBatis,       MyBatis 是一个基于Java的持久层框架.( ...