CodeForces702B Powers of Two

【硬件设计】_基于STM32单片机的智能台灯系统 智能台灯系统是一款多功能的智能照明设备,能够自动调节亮度、监测人体活动、感知环境光照,并具备定时和报警功能,极大提升了用户体验与功能的灵活性,主要包括以下功能:系统提供自动和手动两种模式以调节台灯亮度。在自动模式下,台灯会根据周围光强智能调整;而在手动模式下,用户可通过按键自行设置亮度。利用红外光电开关检测台灯与用户之间的距离,若距离过近,系统将发出报警提示。通过时钟模块设置定时提醒,并在OLED显示屏上显示当前时间,当达到设定的定时时间时,蜂鸣器将发出报警音。 阅读详情
You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).
Input
The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Output
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
Examples
input
4
7 3 2 1
output
2
input
3
1 1 1
output
3
Note
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).

In the second example all pairs of indexes (i, j) (where i < j) include in answer.


题意就是求一些数中两个数之和为2的幂的对数有多少。

如果直接枚举的话必然超时。

由于int范围内2的幂的个数很少,可以考虑对于一个数 i ,看所有2的幂-i 的数的个数,这些数就是能够与 i 组成2的幂的数,

同时这不可能出现重复或是遗漏,因为两个数之和如果等于2的幂,那么必然在枚举后一个数时将其记录。

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;

map<LL,LL> s;
int main()
{
    int n;
    LL ans=0,t;
    scanf("%d",&n);
    while(n--){
        scanf("%I64d",&t);
        for(int i=0;i<32;i++){
            ans+=s[(1<<i)-t];
        }
        s[t]++;
    }
    printf("%I64d\n",ans);
    return 0;
}





【电路设计实战】BUCK降压电路:从原理到PCB布局的降噪与效率优化 本文深入剖析了BUCK降压电路的工作原理,并针对其固有的开关噪声问题,提供了从核心元件选型到PCB布局的全面优化方案。文章重点探讨了电感、电容等关键元件的选型要点,强调了低ESR电容和肖特基二极管的重要性,并详细阐述了如何通过最小化功率回路、保护敏感信号线等PCB布局实战技巧,有效抑制噪声、提升效率与稳定性。 阅读详情

相关推荐

软件缺陷(定义+表现形式+优先级+信息+产生原因),看完这篇文章就懂了

软件缺陷软件缺陷的定义软件缺陷的表现形式软件缺陷产生的原因软件缺陷的根源软件缺陷的费用软件缺陷的信息 软件缺陷的定义 IEEE 1983 of IEEE Stardard 729中软件缺陷做了一个标准的定义: 从产品内部看,软件缺陷是软件产品开发或维护过程中所存在的错误、毛病等各种问题;从外部看,软件缺陷是系统所需要实现的某种功能的失效或违背。 因此软件缺陷就是软件产品中所存在的问题,最终表现为用户所需要的功能没有完全实现,没有满足用户的需求。 缺陷不是bug,缺陷包含bug,缺陷的范围更大。 软件缺陷

qq_40676418的博客 1万+

CodeForces 702B: Powers of Two(遍历、穷举)

Powers of Two time limit per test: 3 seconds memory limit per test: 256 megabytes inputstandard input outputstandard output   You are given n integers a1, a2, ..., ana_1, a_2, ..., a_n. Find the n

Jerry的博客 576

【脚本篇】---spyglass lint脚本

【代码】【脚本篇】---spyglass lint脚本。

冬瓜 6355

【Codeforces】-702B-Powers of Two(二分)

点击打开链接 B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1,

Bear1998的博客 990

第3讲:单端传输线的时域TDR仿真(基于实战的第一次仿真视角切换)

本文为CST仿真系列教程的第3讲,主要介绍传输线阻抗(TDR)的两种仿真方法:基于S参数的频域计算和基于高斯脉冲的时域计算。文章详细演示了在CST PCB Studio中修改电容参数、设置TDR仿真参数(包括截止时间和采样点数)的操作步骤,并通过对比实验展示TVS寄生电容对阻抗曲线的影响。最后将两种TDR方法的结果进行对比,验证了两种方法的一致性。本教程适合硬件工程师通过时域波形直观分析传输线阻抗特性,是信号完整性分析的重要技能。

一只豌豆象的博客 228

推荐系统(一)概述

在互联网领域,推荐系统(Recommendation Systems)的应用非常广泛。在音视频方面,如抖音、快手、哔哩等;在电商平台方面,如京东、淘宝、拼多多等。推荐有助于帮助用户快速发现潜在感兴趣的内容(音视频、商品、新闻等信息流),从而提升用户体验,同时有助于提升商业效率。从本文开始,笔者将结合自身在信息流推荐领域的经验,通过系列文章对推荐系统展开介绍。

Jin_Kwok的博客 6084

Codeforces 702B Powers of Two

题目链接:http://codeforces.com/problemset/problem/702/B 题意:   给你N个数a0, a1, a2......an-1,问存在几对 <i,j> 满足i < j, ai + aj = 2x ,x可以是任意整数. 思路:     最容易想到的是把这 n 个数全部两两加起来,然后判断是否是 2 的幂,但是这需要O(n2...

dimaishu7553的博客 263

sap资产post记录查询时候 报错 如图

SAP资产过账查询报错AA653解决方案摘要 错误原因:系统无法计算会计年度期间的最后一天,导致资产折旧/过账失败。常见原因包括:1)未创建2025年期间版本;2)期间日期映射不完整;3)依赖日历但未生成2025年日历。 解决方法: 通过OB37维护2025年12/13个完整期间 补充缺失期间或修正结束日期 使用SCAL生成2025年工厂日历 验证步骤: 检查T009R表2025年记录完整性 测试AFAB折旧运行 重新查询资产过账 提示:建议财务团队统一维护跨年度期间数据,并在测试系统验证变更。

金牌架构师 834

【CodeForces】702B - Powers of Two 数据结构Map

http://codeforces.com/problemset/problem/702/B给n个数,求有几对数能构成2的n次方(n<32)。灵活使用Map。#include <bits/stdc++.h> using namespace std;int n; int x; long long ans; map <int,int> m;int main(){ cin >> n; f

西瓜不甜的博客 305

18、近端策略优化(PPO)算法详解

本文详细介绍了近端策略优化(PPO)算法的理论基础、算法流程、实现方法及实际应用。PPO作为当前最受欢迎的策略梯度算法之一,具有易于实现、计算成本低、样本效率高和性能优越等优点。文章对比了基于自适应KL惩罚和基于裁剪目标的两种PPO变体,重点解析了裁剪目标函数的设计原理及其在Actor-Critic框架下的实现方式,并通过Atari Pong游戏展示了完整的训练配置与流程。最后总结了PPO的优势、适用场景及未来发展方向,为强化学习研究者和实践者提供了全面的参考。

mongodb5scout的博客 180

海格通信嵌入式面试题及参考答案

计算电路的最高工作频率如何计算? 计算电路的最高工作频率主要考虑电路中的关键路径延迟。关键路径是指在整个电路中,信号传播延迟最长的路径。电路的最高工作频率的倒数就是时钟周期,而时钟周期必须大于关键路径的延迟时间。 首先要确定电路中各个模块的延迟。比如对于组合逻辑电路,可以通过查看芯片手册获取门电路的延迟参数。以一个简单的与门、或门、非门组成的组合逻辑为例,每个门都有自己的传输延迟,把信号从输入到输出经过的所有门的延迟相加,就得到这部分组合逻辑的延迟。 对于包含寄存器的电路,还需要考虑寄

大模型大数据攻城狮的专栏 1271

Codeforces 702B - Powers of Two

B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1, a2, ..., an.

nare123的博客 890

Debezium 性能调优实战:吞吐量、延迟与资源平衡

摘要: 本文分享了团队如何通过系统性调优将Debezium从初始3,200 TPS/2.8秒延迟提升至15,200 TPS/210ms延迟的实战经验。优化涵盖四个层面:1)Debezium连接器配置(批处理、快照并行、消息精简);2)Kafka分区策略与Avro序列化缓存;3)JVM改用ZGC及OS参数调优;4)MySQL的binlog与I/O优化。关键发现包括分区数黄金公式、sync_binlog调整带来56%的I/O负载下降,以及避免盲目增大队列内存等陷阱。最终实现吞吐量提升4.75倍,并强调性能调优需

爱丹丹的博客 358

CodeForces 702B Powers of Two(二分)

B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are givennintegersa1, a2, ..., an. Find the number of pai...

lee371042的博客 359

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces 702B. Powers of Two

题目连接:http://www.codeforces.com/problemset/problem/702/B 题意:给定n个数,判断有多少个数对(i, j)满足存在x且ai+aj=2xa_i+a_j=2^x。其中1≤n≤1051\le n \le10^5,1≤ai≤1091\le a_i \le10^9。 想法:由于1≤ai≤1091\le a_i \le10^9,故我们可枚举x,再查询2x−

你是我天边最美的云彩~~ 476

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

CodeForces - 702B Powers of Two(暴力)

题目: 传送门 思路: 根据数据范围 ,可以发现 2k 的数不超过 40 个,我们所以我们暴力枚举即可 long long a[100050]; std::vector<long long> v; map<long long,int> s; int main() { long long k=1; while(k<=2e9) { v....

JingluoZZZ 366

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

CodeForces - 702B Powers of Two

B. Powers of Twotime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j...

qq_37621623的博客 351

Codeforces 702 B Powers of Two

B. Powers of Twotime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j...

Sizaif's 小屋 400

Powers of Two CodeForces - 702B

You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i &lt; j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x). Input T...

七九河开的博客 313

codeforces 702B - Powers of Two

You are givennintegersa1, a2, ..., an. Find the number of pairs of indexesi, j(i j) thatai + ajis a power of2(i. e. some integerxexists so thatai + aj = 2x). Input The fir

ShiWaiGaoRen12345的博客 534

从零手写DDPM:深入理解扩散模型底层原理与实现

扩散模型通过前向加噪与反向去噪的马尔可夫链实现图像生成,其核心在于噪声调度与U-Net架构的协同。前向过程将图像逐步溶解为高斯噪声,反向过程则训练神经网络预测噪声并逐步还原。这种基于MSE的简洁训练目标避免了对抗训练的不稳定性,同时时间步嵌入与注意力机制显著提升了生成质量。在图像生成、编辑与超分辨率等场景中,扩散模型展现出强大的建模能力。本文从零手写DDPM,详细拆解加噪去噪公式、U-Net实现与训练采样全流程,帮助读者彻底掌握扩散模型底层细节。

weixin_33868027的博客 307

Codeforces 702 B. Powers of Two(二分)

传送门 B. Powers of Two time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given n integers a1, a2, …, an. Find the number of pairs o

代码改变世界 1889

【CodeForces】702B - Powers of Two(二分)

点击打开题目 B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1,

wyg1997 679

codeforces 702B B. Powers of Two(水题)

题目链接: B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are givennintegersa1, a2, ..., an. F...

weixin_30929195的博客 265

CodeForces 702B Powers of Two【二分/lower_bound找多少个数/给出一个数组 求出ai + aj等于2的幂的数对个数】...

B. Powers of Two You are givennintegersa1, a2, ..., an. Find the number of pairs of indexesi, j(i < j) thatai + ajis a power of2(i. e. some integerxexists so thatai + aj = 2x)....

weixin_30832405的博客 147

Codeforces Educational Codeforces Round 15 B. Powers of Two

B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n integers a1, a2, ..., an. F...

148
上一篇: POJ1569 Myacm Triangles 判断点与三角形的关系
下一篇: NYOJ55 懒省事的小明
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值