CF1005C Summarize to the Power of Two 暴力 map
3 seconds
256 megabytes
standard input
standard output
A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai, there exists an element ajaj (i≠ji≠j) such that ai+ajai+aj is a power of two (that is, 2d2d for some non-negative integer dd).
For example, the following sequences are good:
- [5,3,11][5,3,11] (for example, for a1=5a1=5 we can choose a2=3a2=3. Note that their sum is a power of two. Similarly, such an element can be found for a2a2 and a3a3),
- [1,1,1,1023][1,1,1,1023],
- [7,39,89,25,89][7,39,89,25,89],
- [][].
Note that, by definition, an empty sequence (with a length of 00) is good.
For example, the following sequences are not good:
- [16][16] (for a1=16a1=16, it is impossible to find another element ajaj such that their sum is a power of two),
- [4,16][4,16] (for a1=4a1=4, it is impossible to find another element ajaj such that their sum is a power of two),
- [1,3,2,8,8,8][1,3,2,8,8,8] (for a3=2a3=2, it is impossible to find another element ajaj such that their sum is a power of two).
You are given a sequence a1,a2,…,ana1,a2,…,an. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.
The first line contains the integer nn (1≤n≤1200001≤n≤120000) — the length of the given sequence.
The second line contains the sequence of integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).
Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all nn elements, make it empty, and thus get a good sequence.
6
4 7 1 5 4 9
1
5
1 2 3 4 5
2
1
16
1
4
1 1 1 1023
0
In the first example, it is enough to delete one element a4=5a4=5. The remaining elements form the sequence [4,7,1,4,9][4,7,1,4,9], which is good.
题意:给你n个数,问去掉几个数后,每个数都被用上与另一个数和为2的幂数
分析:直接暴力枚举每个二的幂数减去当前数的差是否存在于这个数列中,用map存下每个数
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 2e5 + ;
const int mod = 1e9 + ;
typedef long long ll;
ll a[maxn], vis[maxn];
int main() {
ll n;
while( cin >> n ) {
map<ll,ll> mm;
for( ll i = ; i < n; i ++ ) {
cin >> a[i];
mm[a[i]] ++;
}
ll cnt = ;
for( ll i = ; i < n; i ++ ) {
bool flag = false;
for( ll j = <<; j >= ; j /= ) {
if( j > a[i] ) {
if( ( a[i] == j/ && mm[j-a[i]] > ) || ( mm[j-a[i]] > && a[i] != j/ ) ) {
flag = true;
break;
}
}
}
if( !flag ) {
//debug(a[i]), debug(i);
cnt ++;
}
}
cout << cnt << endl;
}
return ;
}
CF1005C Summarize to the Power of Two 暴力 map的更多相关文章
- Summarize to the Power of Two(map+思维)
A sequence a1,a2,…,ana1,a2,…,an is called good if, for each element aiai, there exists an element aj ...
- CF 1005C Summarize to the Power of Two 【hash/STL-map】
A sequence a1,a2,-,an is called good if, for each element ai, there exists an element aj (i≠j) such ...
- Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力
D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of ...
- codeforces 633D D. Fibonacci-ish(dfs+暴力+map)
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard in ...
- luoguP1555 尴尬的数字(暴力+map)
题意 题解 枚举每一个可能的二进制数.扔到一个map里 再枚举每一个可能的三进制数看map有没有就行了 反正就是很水 #include<iostream> #include<cstr ...
- 当超强台风“山竹”即将冲进南海,Power BI 你怎么看?
这个周末“山竹 ”强势来袭!很多人的目光都在关注暴力水果“山竹”,这个号称70年最强最大风力超17级 台风“山竹”今天就已经在小悦家窗台肆虐咆哮了一天了!不知其他的小伙伴们是不是好好的一个周末就只能被 ...
- 在Microsoft Power BI中创建地图的10种方法
今天,我们来简单聊一聊“地图”. 在我们日常生活中,地图地位已经提升的越来越高,出门聚餐.驾驶.坐车.旅行......应运而生的就是各种Map APP. 作为数据分析师,我们今天不讲生活地图,要跟大家 ...
- hdu 3698 Let the light guide us(线段树优化&简单DP)
Let the light guide us Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 62768/32768 K (Java/O ...
- Codeforces Round #496 (Div. 3) ABCDE1
//B. Delete from the Left #include <iostream> #include <cstdio> #include <cstring> ...
随机推荐
- cmd与monkey测试
monkey测试的相关命令 monkey是模拟用户触摸操作,不支持条件判断.monkey命令格式: 启动安卓模拟器/真机 点击运行->输入cmd->进入命令行界面 查看设备连接情况,ad ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- 对于HTTP过程中POST内容加密的解决方案
0x00前言 前几天我师傅和我提及了这件事情 正常情况下 抓包过程中遇到加密情况会很迷茫 昨天把这个都弄了一下 也感谢大佬中间的指导 我一开始看到密码的类型下意识的是base64 但是去解密发现不对 ...
- java中线程安全,线程死锁,线程通信快速入门
一:多线程安全问题 ###1 引入 /* * 多线程并发访问同一个数据资源 * 3个线程,对一个票资源,出售 */ public class ThreadDemo { public static vo ...
- luogu1330_封锁阳光大学 图的遍历
传送门 解释:(转自洛谷题解) 首先,肯定要明确一点,那就是这个图是不一定联通的.于是,我们就可以将整张图切分成许多分开的连同子图来处理.然而最重要的事情是:如何处理一个连通图? 乍看下去,似乎无从下 ...
- 信息收集框架——recon-ng
背景:在渗透测试前期做攻击面发现(信息收集)时候往往需要用到很多工具,最后再将搜集到的信息汇总到一块. 现在有这样一个现成的框架,里面集成了许多信息收集模块.信息存储数据库.以及报告 ...
- c# NPOI 导出23万条记录耗时12秒
先上测试代码: string connectionString = "Server=localhost;Initial Catalog=******;User ID=sa;Password= ...
- powerdesigner16.6版本resource的重复使用
今天早上遇到想要重复使用resource ,但是发现powerdesigner16.6版本跟16.5版本有关重复使用name的设置已经不一样了,网上找了好久没找到,软件上找了好久也没找到相应的设置. ...
- JVM(十一):内存分配
JVM(十一):内存分配 在前面的章节中,我们花了大量的篇幅去介绍 JVM 内的内存布局.对象在内存中的状态.垃圾回收的算法和具体实现等.今天让我们探讨一下对象是如何分配内存的. 堆内存划分 前面说过 ...
- Windows Server 2008配置系统安全策略
下面学习Windows Server 2008配置系统安全策略 在工作组中的计算机本地安全策略有 用户策略,密码策略,密码过期默认42天 服务账户设置成永不过期,帐户锁定策略,本地策略,审核策略,计算 ...