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 ...
随机推荐
- Skier 游戏
# Listing_10-1.py # Copyright Warren Sande, 2009 # Released under MIT license http://www.opensource. ...
- 【iOS】获取视图的中心和宽高
示例代码: NSLog(@"%f, %f", self.view.center.x, self.view.center.y); NSLog(@"%f, %f", ...
- 【Machine Learning·机器学习】决策树之ID3算法(Iterative Dichotomiser 3)
目录 1.什么是决策树 2.如何构造一棵决策树? 2.1.基本方法 2.2.评价标准是什么/如何量化评价一个特征的好坏? 2.3.信息熵.信息增益的计算 2.4.决策树构建方法 3.算法总结 @ 1. ...
- 【Python-Django后端开发】配置静态文件详解!!!
配置前端静态文件 1. 准备静态文件 2. 指定静态文件加载路径 STATIC_URL = '/static/' # 配置静态文件加载路径 STATICFILES_DIRS = [os.path.jo ...
- TextView 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- .NET----错误和异常处理机制
前言 错误的出现并不总是编写程序的人的原因,有时应用程序会因为应用程序的最终用户引发的动作或运行代码的环境发生错误.无论如何,我们都应预测应用程序中出现的错误,并相应的进行编码. .Net改进了处理错 ...
- 【游记】NOIP2018初赛
声明 本文最初的版本创建之时,本人甚至只是个电脑的小白,因而不太会用电脑编辑文字,最初的版本写在一个Word文档里,被随意的丢弃在我杂乱无比的网盘的某一个角落,直到我决定整理自己的成长历程,将散落的游 ...
- 阿里P8Java大牛仅用46张图让你弄懂JVM的体系结构与GC调优。
本PPT从JVM体系结构概述.GC算法.Hotspot内存管理.Hotspot垃圾回收器.调优和监控工具六大方面进行讲述.图文并茂不生枯燥. 此PPT长达46页,全部展示篇幅过长,本文优先分享前十六页 ...
- Java连载14-补码简介&浮点型整数
一.补码简介 1.计算机中的符号数有三种表示方式,即为:原码.反码.补码.三种表示方法均有符号位和数值位,符号位都是0表示正数,符号位都是1表示负数. 2.计算机中的数字的存储方式:在计算机系统中,数 ...
- 从源码看Flask框架配置管理
1 引言 Flask作为Python语言web开发的三大顶梁柱框架之一,对于配置的管理当然必不可少.一个应用从开发到测试到最后的产品发布,往往都需要多种不同的配置,例如是否开启调试模式.使用哪个数据库 ...