传送门: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. C# StackTrace

    StackTrace trace = new StackTrace(); //获取是哪个类来调用的 Type type = trace.GetFrame().GetMethod().Declaring ...

  2. set和map结构,class类

    1.set数据结构和map数据结构: (1)set: 数据结构set(集合,无序且值不能重复的数据集合,特点是key值和value值相同,没有重复的value //1 创建set ,,]) conso ...

  3. 入门MySQL——基础语句篇

    前言:  前面几篇文章,我们介绍了MySQL的基础概念及逻辑架构.相信你现在应该有了自己的一套MySQL环境,接下来我们就可以开始练习MySQL了.本文将从MySQL最基础的语句出发,为你展示出创建及 ...

  4. powermockito单元测试之深入实践

    概述 由于最近工作需要, 在项目中要做单元测试, 以达到指定的测试用例覆盖率指标.项目中我们引入的powermockito来编写测试用例, JaCoCo来监控单元测试覆盖率.关于框架的选择, 网上讨论 ...

  5. 算法与数据结构基础 - 链表(Linked List)

    链表基础 链表(Linked List)相比数组(Array),物理存储上非连续.不支持O(1)时间按索引存取:但链表也有其优点,灵活的内存管理.允许在链表任意位置上插入和删除节点.单向链表结构一般如 ...

  6. java常见面试题目(二)

    部分没有答案可以自行百度. 1.myeclipse与eclipse的区别. 2.说说对maven或者SVN的理解. 3.类的加载过程 (创建对象的过程)  1)子父类里静态属性 赋上默认初始值 如果有 ...

  7. js中判断一个对象的类型的种种方法

    javascript中检测对象的类型的运算符有:typeof.constructor.instanceof. typeof:typeof是一个一元运算符,返回结果是一个说明运算数类型的字符串.如:&q ...

  8. 【Java例题】5.5 两个字符串中最长公共子串

    5. 查找两个字符串中含有的最长字符数的公共子串. package chapter5; import java.util.Scanner; public class demo5 { public st ...

  9. 浅谈微服务架构与服务治理的Eureka和Dubbo

    前言 本来计划周五+周末三天自驾游,谁知人算不如天算,周六恰逢台风来袭,湖州附近的景点全部关停,不得已只能周五玩完之后,于周六踩着台风的边缘逃回上海.周末过得如此艰难,这次就聊点务虚的话题,一是浅谈微 ...

  10. java并发编程(二十五)----(JUC集合)LinkedBlockingDeque和ConcurrentLinkedDeque介绍

    Queue除了前面介绍的实现外,还有一种双向的Queue实现Deque.这种队列允许在队列头和尾部进行入队出队操作,因此在功能上比Queue显然要更复杂. LinkedBlockingDeque 我们 ...