"Parity算法详解:利用sum数组判断奇偶性,通过并查集解决矛盾问题"
需积分: 20 75 浏览量
更新于2024-01-13
收藏 812KB PPT 举报
The Parity(ceoi99) algorithm, devised by Xiao Tian, involves establishing an array called sum, where sum[i] represents whether the sum from 1 to i is odd (true) or even (false), with sum[0] initialized as false. This allows any given question (a,b) to be expressed using the expression sum[b] xor sum[a-1].
Initially, the values of sum[1..n] are unknown and assumed to be false, meaning that any sum[a] and sum[b] are independent. For each question (a,b,c), we can determine the relationship between sum[b] and sum[a-1] by using the equation sum[b] xor sum[a-1]=c. This step can be performed using a disjoint-set data structure. If sum[a-1] and sum[b] do not belong to the same set for a given question, they are merged into the same set. If sum[a-1] xor sum[b] does not equal c, a contradiction is detected, and the total sentence count is output before exiting.
For a consistent sum array without contradictions, each set is divided into two parts, with one part designated as true and the other as false. This allows for the determination of the sum array. Using the equation sum[i] xor sum[i-1], we can calculate the value of the ith digit. Since there are no questions asked between different sets, this sequence of numbers represents a valid solution, proving the correctness of the algorithm. It is often used in various algorithms.
2022-07-15 上传
104 浏览量
133 浏览量
806 浏览量
2021-05-15 上传
111 浏览量
我的小可乐
- 粉丝: 26
- 资源: 2万+
最新资源
- 测试一下
- 倒霉熊图标下载
- SETFSB.zip
- marathon_3:免费的智力马拉松HTML-学院
- BlenderGEResourceKit:Blender游戏引擎的即用型组件集合
- winsdksetup.zip
- Aikatsu LGTM-crx插件
- dsm-htpc-群集
- simple-password-manager:Flutter制作的简单密码管理应用
- 精美蝴蝶图标下载
- 电信设备-带身份核验的物联网移动终端及人证合一核验方法.zip
- 初级java笔试题-cs-study:https://github.com/jwasham/coding-interview-universi
- MinGW压缩包省去繁琐的官网下载
- SYIPAGeneratedScript:make a ipa by script——使用脚本生成ipa包
- VTS Testing Version 2-crx插件
- 帮手