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. 2022-01-01:给定int[][] meetings,比如 { {66, 70} 0号会议截止时间66,获得收益70 {25, 90} 1号会议截止时间25,获得收益90

    2022-01-01:给定int[][] meetings,比如 { {66, 70} 0号会议截止时间66,获得收益70 {25, 90} 1号会议截止时间25,获得收益90 {50, 30} 2号 ...

  2. MultiBoot SPI

    对于7系列FPGA来说,计算器件启动时间按照以下公式: Config time = Bitstream size / (Config clk freq * Config interface width ...

  3. < Python全景系列-4 > 史上最全文件类型读写库大盘点!什么?还包括音频、视频?

    欢迎来到我们的系列博客<Python全景系列>!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语言! 本文系列第四篇,介绍史上 ...

  4. 《HelloGitHub》第 86 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  5. 有管django使用orm 字段报错问题

    直接删除表,重新生成,首先删除:migrations 中,上传记录,然后django_migrations,

  6. uniapp 全局背景音乐播放+暂停(跳转页面不暂停)

    最近需要一个功能 是在h5中播放小游戏的背景音乐,但是跳转界面之后音乐不暂停,就是跳转多个页面之后,音乐依然在播放,在游戏界面会有设置的静音的按钮,可以开启音乐和关闭音乐. 单独建了一个music.j ...

  7. .NET的基元类型包括哪些?Unmanaged和Blittable类型又是什么?

    在讨论.NET的类型系统的时候,我们经常提到"基元类型(Primitive Type)"的概念,我发现很多人并没有真正理解基元类型就究竟包含哪些(比如很多人觉得字符串是基元类型). ...

  8. malloc/free 与 new/delete

    malloc/free与new/delete表达式的区别?相同点: 都是用来申请堆空间不同点: 1. malloc/free是库函数; new/delete是表达式 2. malloc开空间时,并不会 ...

  9. vivo 帐号服务稳定性建设之路-平台产品系列06

    作者:vivo 互联网平台产品研发团队- Shi Jianhua.Sun Song 帐号是一个核心的基础服务,对于基础服务而言稳定性就是生命线.在这篇文章中,将与大家分享我们在帐号稳定性建设方面的经验 ...

  10. JVM、JRE和JDK的理解

    JVM JVM,全称为Java Virtual Machine,中文的意思是:Java虚拟机.   在理解Java虚拟机这个定义之前,我们先讲讲为何叫虚拟机呢?称为虚拟机,顾名思义,它应该不是真实存在 ...