Codeforces 988D Points and Powers of Two 【性质】【卡常】
这道题关键在于想到两个性质,想到就好做了。这还是我做过的第一道卡常题
1.满足题目中条件的子集,其中元素个数不能大于3
2.如果最大子集为3的话,那一定是x-2^i, x, x+2^i的形式,我们枚举x就好了,然后i的次数是log10^9;如果最大子集是2,那就是x,x+2^i的形式,同样枚举x;如果最大子集是1,输出a[1]就行
可以用set来判断一个数存不存在
整体复杂度是O(n*logn*log10^9)
1 #include<iostream> 2 #include<set> 3 using namespace std; 4 5 int a[200005]; 6 set<int> m; 7 8 int main(){ 9 int n,size=0; cin>>n; 10 int x1,x2; 11 for(int i=1;i<=n;i++) { 12 cin>>a[i]; 13 m.insert(a[i]); 14 } 15 for(int i=1;i<=n;i++){ 16 for(int j=0;j<31;j++) { 17 if( m.count( a[i]+(1<<j) ) && m.count( a[i]-(1<<j) ) ){ 18 cout<<3<<endl; 19 cout<<a[i]<<" "<<a[i]+(1<<j)<<" "<<a[i]-(1<<j); 20 return 0; 21 } 22 if( m.count( a[i]+(1<<j) ) && size==0) { 23 size = 2; 24 x1 = a[i]; 25 x2 = a[i] + (1 << j); 26 } 27 } 28 } 29 if(size==2) cout<<2<<endl<<x1<<" "<<x2; 30 else cout<<1<<endl<<a[1]; 31 32 return 0; 33 }
转载于:https://www.cnblogs.com/ZhenghangHu/p/9129422.html
Codeforces 988D Points and Powers of Two 【性质】【卡常】相关推荐
- CodeForces - 76E Points
CodeForces - 76E Points 题意: 给你n个点的坐标,求所有一对点之间的距离的平方和 n<=100000 题解: 直接暴力n2肯定不行,我们把这个的式子列出来: 代码: #i ...
- D. Points and Powers of Two
https://codeforces.com/problemset/problem/988/D 题目描述 There are nn distinct points on a coordinate li ...
- Codeforces Round #638 div2 A(等比数列的性质,循环求解)
A. Phoenix and Balance 题意: 要你把一个等比数列,平均分成两堆,要求和的差值最小 思路: 等比数列的一个性质:a[i]>sum[i-1](第i项大于前i-1项的和) 所以 ...
- CF988 D. Points and Powers of Two【hash/数学推理】
[链接]:CF [题意]:从一堆数中选一个最大子集,使得任意两个数相减的绝对值都是2的幂. [分析]:首先很难的一点,需要想到子集最多只能有三个,四个及以上的子集一定不存在(可以证明).当有三个元素时 ...
- Codeforces 1646C Factorials and Powers of Two
0x10 题目链接 cf 1646c 0x20 题目 0x21 Tag 状态压缩,枚举 0x22 题目描述 0x23 翻译 给出一个数n,是否能将其拆解成多个**(共k个)**2的幂次与阶乘的和,求k ...
- CodeForces - 1646C Factorials and Powers of Two
看了大佬的博客才会写的 传送门 #include<bits/stdc++.h> using namespace std;#define int long longint lowbit(in ...
- CodeForces 305C Ivan and Powers of Two【set】
这个题啊,纠结了本公举一中午,知道如果出现了重复的,就要往后移,差点就把自己想的恶心的bool 数组付诸实现了,== 既然是思维的题,借助了STL的特性是再正常不过的了,既然想写数组,先应该想想Set ...
- 【CodeForces - 190E】Counter Attack (补图bfs,卡常,dsu)
题干: 无向图中给定n个顶点,m条不存在的边(除了这m条边,其余都存在),求图的连通分量,及每个连通分量的大小. 解题报告: https://codeforces.com/blog/entry/455 ...
- 【CodeForces - 195D】Analyzing Polyline (思维,卡精度的处理方式)
题干: As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, th ...
- 【CodeForces - 1027C】Minimum Value Rectangle (数学,公式化简,思维,卡常卡memset)
题干: You have nn sticks of the given lengths. Your task is to choose exactly four of them in such a w ...
最新文章
- 清华大学提出点云Transformer!在3D点云分类、分割上表现优秀,核心代码已开源!...
- linux间隔时间执行,科技常识:使用linux命令crontab间隔时间执行其它命令
- excel像素画教程_像素画新手教程:极简像素画角色分析
- 【虚拟主机篇】asp页面实现301重定向方法
- Spring Cloud构建微服务架构:服务容错保护(Hystrix依赖隔离)【Dalston版】
- 高等微積分(高木貞治) 1.4節 例2
- twisted系列教程二–缓慢的诗
- VC++使用管道重定向进程输入输出(附源码)
- selenium测试框架快速搭建(ui自动化测试)
- ZooKeeper示例 实时更新server列表
- HTML、CSS、JavaScript学习总结
- 判断全角与半角及两者之间的转换
- sql语句中调用将汉字转换为拼音函数
- MySQL数据查询(可视化界面 MySQL Workbench)
- 宏定义(无参,有参,宏函数)(详细介绍)
- js从路径中遍历出文件或图片名称,js截取路径中的图片和文件名称
- 有趣的第一人称和第三人称游戏
- linux移动硬盘hd0,u盘/移动硬盘(usb hd)安装多种linux live CD
- spring注解驱动开发-6 Spring AOP实现原理
- 国内在线漫画快速发展,快看、Bilibili布局海外,国漫出海正当时