2023-01-15

题目

题目传送门

翻译

翻译

难度&重要性(1~10):4

题目来源

AtCoder

题目算法

dp/模拟

解题思路

我们都知道,异或是一种不进位的加法,而要想 $ a + b = a \oplus b $ 就不能进位,也就是说每一位不能是 $ ( 1,1 ) $ 就有 $ ( 0,1 ),( 1,0 ),( 0,0 )$ 三种可能。

举例: $ 10 ,11 $ 是不可行的,因为它会进位,而 $ 100,010 $ 就可以。

然后,我们需要让它满足 $ a+b \le L $ 即 $ a \oplus b \le L $ 而我们都知道,比较两个数的大小,是从高位往低位比较的。所以我们只需要保证 $ a \oplus b $ 中第 \(k\) 位小于 \(L\) 前面的一样,后面的位数可以随便填,其方案数为 \(3^{k}\)。因为异或 \(1\) 有两种方案 $ ( 0,1 ),( 1,0 ) $ 所以前面部分方案数为 $ 2^{n-k-1} $。

完成状态

已完成

[ABC129E] Sum Equals Xor的更多相关文章

  1. AtCoder ABC 129E Sum Equals Xor

    题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_e 题目大意 给定一个二进制表示的数 L,问有多少对自然数 (a, b) 满足 $a + b ...

  2. Subarray Sum & Maximum Size Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

  3. [leetcode-560-Subarray Sum Equals K]

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  4. LeetCode 560. Subarray Sum Equals K (子数组之和等于K)

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. Sum of xor

    Sum of xor jdoj-2160 题目大意:给你一个n,求1^2^...^n. 注释:$n<=10^{18}$. 想法:第一道异或的题.先来介绍一下什么是异或.a^b表示分别将两个数变成 ...

  6. [LeetCode] Subarray Sum Equals K 子数组和为K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  7. [Swift]LeetCode560. 和为K的子数组 | Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  8. LeetCode - Subarray sum equals k

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  9. 560. Subarray Sum Equals K 求和为k的子数组个数

    [抄题]: Given an array of integers and an integer k, you need to find the total number of continuous s ...

  10. Subarray Sum & Maximum Size Subarray Sum Equals K && Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

随机推荐

  1. ModuleNotFoundError: No module named 'flask_wtf'

    ModuleNotFoundError: No module named 'flask_wtf' 解决: pip install flask_wtf

  2. MMCM and PLL Dynamic Reconfiguration

    Reconfiguration is performed through the DRP. The DRP provides access to the configuration bits that ...

  3. 计算机网络 VRRP和DHCP

    目录 一.vrrp概念 二.vrrp工作过程 三.vrrp优先级 四.vrrp实验 五.DHCP概念 六.DHCP工作过程 七.DHCP实验 一.vrrp概念 概念:称虚拟路由器冗余协议,当网关路由器 ...

  4. 【python基础】复杂数据类型-列表类型(数值列表)

    1.数值列表 列表非常适合用于存储数字集合,而python提供了很多工具,可帮助我们高速地处理数字列表. 1.1 range函数 python的range函数能够轻松的生成连续一系列数字. 其语法格式 ...

  5. Python之Excel表格数据处理

    正式开讲之前,我们需要先了解几个基本的知识点:1.Python字典(Dictionary) 的setdefault()方法描述:如果键不存在于字典中,将会添加键并将值设为默认值.语法:dict.set ...

  6. ORM总览

    ORM(Object-Relational Mapping)是一种常见的数据访问技术,它将对象模型和关系模型之间进行映射.ORM的主要作用是简化数据访问和管理,提高开发效率和代码质量.在实际应用中,O ...

  7. Prompt 手册——gpt-best-practices

    本文链接:https://www.cnblogs.com/wanger-sjtu/p/17470388.html 本文是 OpenAI gpt-best-practices 对如何使用GPT的Prom ...

  8. 基于FFMPEG+SDL的简单的视频播放器分析

    基于FFMPEG+SDL的简单的视频播放器分析 前言 最近看了雷霄骅前辈的博客<最简单的基于FFMPEG+SDL的视频播放器 ver2 (采用SDL2.0)>,参照他的代码,在window ...

  9. 【WALT】update_task_demand() 代码详解

    目录 [WALT]update_task_demand() 代码详解 代码展示 代码逻辑 用于判断是否进入新窗口的标志位 ⑴ 不累加任务运行时间的条件判断 ⑵ 仍在旧窗口中 ⑶ 进入新窗口 ⑷ 返回值 ...

  10. 2023年最具威胁的25种安全漏洞(CWE TOP 25)

    摘要: CWE Top 25 是通过分析美国国家漏洞数据库(NVD)中的公共漏洞数据来计算的,以获取前两个日历年 CWE 弱点的根本原因映射. 本文分享自华为云社区<2023年最具威胁的25种安 ...