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> ...
随机推荐
- ubuntu搭建环境
1.终端输入 sudo apt- add-apt-repository ppa:ondrej/php sudo add-apt-repository ppa:ondrej/php sudo apt ...
- 蓝桥杯 2n皇后问题 深搜
默认大家会了n皇后问题 基础练习 2n皇后问题 时间限制:1.0s 内存限制:512.0MB 问题描述 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和 ...
- python log 设置
# -*- coding: utf-8 -*- import loggingfrom logging.handlers import TimedRotatingFileHandler # 按时间处理 ...
- koa2基于stream(流)进行文件上传和下载
阅读目录 一:上传文件(包括单个文件或多个文件上传) 二:下载文件 回到顶部 一:上传文件(包括单个文件或多个文件上传) 在之前一篇文章,我们了解到nodejs中的流的概念,也了解到了使用流的优点,具 ...
- 3PHP如何用PDO的连接方式方式导出mysql数据
首先连接mysql,具体看上一篇 接下来在try{}中加入以下代码 $query="select * from 你的数据表名称" //$query的内容给个SQL ...
- 使用python画3D线条
"""用于验证整体趋势正确性""" #!python3 #-*- coding:utf-8 -*- import matplotlib as ...
- postman-使用教程
postman postman是一款非常方便的API测试工具,可以帮我们快速的发起HTTP请求,下面记录一下postman的基本使用. postman安装 postman下载地址 下载安装打开之后就是 ...
- 帝国CMS(EmpireCMS) v7.5后台getshell分析(CVE-2018-18086)
帝国CMS(EmpireCMS) v7.5后台getshell分析(CVE-2018-18086) 一.漏洞描述 EmpireCMS 7.5版本及之前版本在后台备份数据库时,未对数据库表名做验证,通过 ...
- SQL Server 数据完整性的实现——约束
SQL Server数据库采用的是关系数据模型,而关系数据模型本身的优点之一就是模型本身集成了数据完整性.作为模型一部分而实施的数据完整性(例如在创建数据表时的列属性定义)称作为声明式(Declara ...
- 还在用if else?策略模式了解一下!
在公司负责的就是订单取消业务,老系统中各种类型订单取消都是通过if else 判断不同的订单类型进行不同的逻辑.在经历老系统的折磨和产品需求的不断变更,决定进行一次大的重构:消灭 if else. 接 ...