HBC223615[NOIP1998]阶乘之和,暴力GOutofSorts题解

云中君 算法基础篇 79 0
全网最全C++题库,助您快速提升编程技能!题库丰富多样,涵盖各个领域,让您在练习中不断成长!
Needless to say, this means that many values that are in the array will not be found by a binary search, although surprisingly some can. In the example above, both 4 and 7 can be found with Ann’s binary search. How many values can be found for various sequences?

Ann Logan is fascinated with finite sequences of integers. She is particularly interested in sequences of the form x1, x2, . . . , xn where:      • xi = (axi−1 + c) mod m,      • n, m, a, and c are positive integer constants,      • x0 is a non-negative integer constant, and      • all n values are unique.  For example, if n = 5, m = 8, a = 1, c = 3, and x0 = 3, the sequence is 6, 1, 4, 7, 2 (x1 = (1 · 3 + 3) mod 8 = 6, x2 = (1 · 6 + 3) mod 8 = 1, and so on). Note that she does not consider the initial value x0 to be part of the sequence.  Ann wants to be able to quickly determine, for any integer value, whether or not it appears within a finite sequence of this form. Given values of n, m, a, c, and x0, she plans to follow this list of steps:      1. Generate the sequence x1, · · · , xn and store it in an array.      2. Sort the array.      3. Perform a binary search of the array for each integer of interest to her.  Ann’s search algorithm, while not the most efficient possible, is pretty straightforward and understandable to anyone familiar with binary search: after calculating the midpoint mid at each step of the calculation (using mid = (low+high)/2), she first checks whether or not the value at location mid is equal to the search value x. If not, she then narrows the search according to whether x is strictly less than or strictly greater than the value at location mid. Unfortunately, Ann is absent-minded and she lost her list of steps. She managed to remember the first and last step, but . . . she forgot to sort the array before performing her binary search! Needless to say, this means that many values that are in the (unsorted) array will not be found by a binary search, although surprisingly some can. In the example above, both 4 and 7 can be found with Ann’s binary search. How many values can be found for various sequences? Don’t botch it up!

HBC223615[NOIP1998]阶乘之和,暴力GOutofSorts题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC223615[NOIP1998]阶乘之和 暴力GOutofSorts题解