[ABC129E] Sum Equals Xor
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的更多相关文章
- AtCoder ABC 129E Sum Equals Xor
题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_e 题目大意 给定一个二进制表示的数 L,问有多少对自然数 (a, b) 满足 $a + b ...
- 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 ...
- [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 ...
- 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 ...
- Sum of xor
Sum of xor jdoj-2160 题目大意:给你一个n,求1^2^...^n. 注释:$n<=10^{18}$. 想法:第一道异或的题.先来介绍一下什么是异或.a^b表示分别将两个数变成 ...
- [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 ...
- [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 ...
- LeetCode - Subarray sum equals k
Given an array of integers and an integer k, you need to find the total number of continuous subarra ...
- 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 ...
- 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 ...
随机推荐
- 2022-03-20:给定一棵多叉树的头节点head, 每个节点的颜色只会是0、1、2、3中的一种, 任何两个节点之间的都有路径, 如果节点a和节点b的路径上,包含全部的颜色,这条路径算达标路径, (
2022-03-20:给定一棵多叉树的头节点head, 每个节点的颜色只会是0.1.2.3中的一种, 任何两个节点之间的都有路径, 如果节点a和节点b的路径上,包含全部的颜色,这条路径算达标路径, ( ...
- Django4全栈进阶之路4 APP注册
在 Django 4 中,应用(app)的注册是通过在项目的 settings.py 文件中添加应用名称来实现的.具体步骤如下: 在项目的根目录下创建一个应用目录,该目录应包含一个 apps.py 文 ...
- ModuleNotFoundError: No module named 'flask_sqlalchemy'
ModuleNotFoundError: No module named 'flask_sqlalchemy' 解决: pip install flask_sqlalchemy
- Element-DatePicker的宽度
Element如何修改DatePicker的宽度 方法/步骤 1 打开一个vue文件,添加DatePicker日期选择器组件,设置默认日期为null.如图 2 在组件上添加style样式属性,设置wi ...
- Jan 2023-Prioritizing Samples in Reinforcement Learning with Reducible Loss
1 Introduction 本文建议根据样本的可学习性进行抽样,而不是从经验回放中随机抽样.如果有可能减少代理对该样本的损失,则认为该样本是可学习的.我们将可以减少样本损失的数量称为其可减少损失(R ...
- 修改本地hosts
本地hosts文件地址 C:\Windows\System32\drivers\etc 修改前 修改后 可以使用记事本打开hosts文件或使用Notepad++ 工具打开 按图示添加,修改即可
- 多线程合集(三)---异步的那些事之自定义AsyncTaskMethodBuilder
引言 之前在上一篇文章中多线程合集(二)---异步的那些事,async和await原理抛析,我们从源码去分析了async和await如何运行,以及将编译后的IL代码写成了c#代码,以及实现自定义的Aw ...
- 代码随想录算法训练营Day24 回溯算法| 理论基础 77. 组合
代码随想录算法训练营 回溯 什么是回溯法 回溯法也可以叫做回溯搜索法,它是一种搜索的方式. 在二叉树系列中,我们已经不止一次,提到了回溯,例如二叉树:以为使用了递归,其实还隐藏着回溯. 回溯是递归的副 ...
- ASP.NET Core 6框架揭秘实例演示[39]:使用最简洁的代码实现登录、认证和注销
认证是一个确定请求访问者真实身份的过程,与认证相关的还有其他两个基本操作--登录和注销.ASP.NET Core利用AuthenticationMiddleware中间件完成针对请求的认证,并提供了用 ...
- tvm relay IR 可视化
本文地址: https://www.cnblogs.com/wanger-sjtu/p/16819877.html 发现最近relay 的可视化已经在tvm主线上支持了,这里有一个简单的demo代码记 ...