Codeforces Round #486 (Div. 3)988D. Points and Powers of Two
传送门: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的更多相关文章
- 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 ...
- 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 ...
随机推荐
- S3 介绍
S3 是ceph rgw的基础,在学习RGW之前,先了解S3.
- hive数仓客户端界面工具
1.Hive的官网上介绍了三个可以在Windows中通过JDBC连接HiveServer2的图形界面工具,包括:SQuirrel SQL Client.Oracle SQL Developer以及Db ...
- 最基础的 ant build 脚本
最基础的 ant build 脚本,根据项目,自行进行修改 <?xml version="1.0" encoding="UTF-8" ?> < ...
- JAVA基础知识(六)Java 静态多分派&动态单分派
1.分派发生在编译期和运行期,编译期的分派为静态分派,运行期的为动态分派. 2.编译期是根据对象声明的类型来选择方法,运行期是根据对象实际类型来选择方法. 3.单分派和多分派取决于宗量, 方法调用者和 ...
- Element UI系列:Select下拉框实现默认选择
实现的主要关键点在于 v-mode 所绑定的值,必须是 options 数组中对应的 value 值
- 10分钟安装Elasticsearch
关注公众号 itweknow,回复"ES"获取<Elasticsearch权威指南 中文版>. 最近在尝试着搭建一个ELK(一个开源的实时日志分析平台),而本文所讲的E ...
- android ——ListView
谷歌官方文档的介绍:https://developer.android.com/reference/android/widget/ListView.html 显示可垂直滚动的视图集合,其中每个视图都立 ...
- golang常用的http请求操作
之前用python写各种网络请求的时候写的非常顺手,但是当打算用golang写的时候才发现相对来说还是python的那种方式用的更加顺手,习惯golang的用法之后也就差别不大了,下面主要整理了常用的 ...
- 不相交路径[BZOJ1471] 容斥原理 拓扑排序
最近学容斥的时候又碰到一道类似的题目,所以想分享一个套路,拿这题来举例 [题目描述] 给出一个\(N(N\leq 150)\)个结点的有向无环简单图.给出4个不同的点\(a,b,c,d\),定义不相交 ...
- js网页倒计时功能(天,时,分,秒)
给定任何一个时间,然后实现现在到那个时间的倒计时. 下面的例子是显示现在到2019年8月1号0时0分的倒计时: <div class="list"> <span ...