[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 ...
随机推荐
- 2021-04-05:给两个长度分别为M和N的整型数组nums1和nums2,其中每个值都不大于9,再给定一个正数K。 你可以在nums1和nums2中挑选数字,要求一共挑选K个,并且要从左到右挑。返回所有可能的结果中,代表最大数字的结果。
2021-04-05:给两个长度分别为M和N的整型数组nums1和nums2,其中每个值都不大于9,再给定一个正数K. 你可以在nums1和nums2中挑选数字,要求一共挑选K个,并且要从左到右挑.返 ...
- 【Java】水果超市管理系统
前言 说是个系统,看着像实训的产物,但实际上这是Java课程最后一个关于jdbc的大实验,yes,挺大的. 过程 看着视频里的一堆一堆的文件,逻辑混乱的讲解,我决定 我自己写这个系统 说干就干: 分析 ...
- AcWing 1209. 带分数
题目描述: 分析: 题意就是说给定一个整数N,求给定a,b,c,求a+b/c==N且a,b,c恰好包括0-9的答案的个数,需要注意的是,b/c可能得到的是小数,所以要尽量避免除法,将等式转换为乘法格式 ...
- 公众号接入 ChatGPT 了!
虽迟但到,用了一段时间的chatgpt,功能确实令人惊叹,也是第一次体验到了交互式编程.不得不说,未来已来,花了一些时间,终于把chatgpt接入到了公众号! 使用方法 打开公众号的对话框,直接提问! ...
- 前端Vue自定义服务说明弹窗弹框 自下而上底部弹框
前端Vue自定义服务说明弹窗弹框 自下而上底部弹框, 请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13108 效果图如下: cc-serv ...
- Jupyter无法运行websocket错误
Juputer无法连接 系websocket连接出问题,浏览器控制台报错 ws 连接异常 WebSocket connection to 'ws://localhost:8888/api/kernel ...
- 解决 Windows 环境下 conda 切换 Python 版本报错 NoWritablePkgsDirError: No writeable pkgs directories configured.
1. 起因 今天运行一个 flask 项目,报错:AttributeError: module 'time' has no attribute 'clock' 一查才发现,Python3.8 不再支持 ...
- JavaCV的摄像头实战之十四:口罩检测
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本文是<JavaCV的摄像头实战> ...
- 介绍Vue router的history模式以及如何配置history模式
引言 Vue router给我们提供了两种路由模式,分别是hash模式和history模式.其中默认是使用hash模式,即URL中带有一个#符号,但是处于业务或个人喜爱的差别,Vue router也提 ...
- [ESP] 使用Ayla API Reference配网和连Ayla云
示例用的文档及链接 US Dev Dashboard(查看oem-id和oem-key) https://dashboard-dev.aylanetworks.com/ Ayla API Refere ...