HBC224024矩阵,枚举,单调队列单调栈,数据结构ProblemB:Folding题解

凌晚轩 算法基础篇 98 0
全网最全C++题库,助您快速提升编程技能!题库丰富多样,涵盖各个领域,让您在练习中不断成长!
There is a transparent tape. Its length is exact one meter (109 nanometers). In this problem, all numbers are integers, and we use a number to denote a position on the tape. The number p den

There is a transparent tape. Its length is exact one meter (109 nanometers). In this problem, all numbers are integers, and we use a number to denote a position on the tape. The number p denote the position of the point has a distance p nanometers from the head of the tape. Bob is a master dyer, so he can color the tape precisely in nanometer scale. He colors two sectors [p1, q1] and [p2, q2] into red. The color of the tape within the range between p1 and q1 is red. The color of the tape within the range between p2 and q2 is also red. And the rest parts of the tape remain transparent.  To verify Bob’s skill, we ask Ben, the tape folding master, to help us. Ben can fold the tape perfectly at any position. If Ben fold the tape at x, then the new position of a certain point p will be one of the following cases. •If p = x, then it becomes the new head of the tape, i.e, it becomes 0. •If p > x, then it becomes p−x. •If p < x, then it becomes x−p. After Ben folds the tape, we measure the total length of the red part of the new tape. If the red part has the expected length, then we will believe Bob and Ben are both masters in their skills. Obviously, the color of some position of the new tape is determined by the colors of the corresponding positions of the old tape. A position of the new tape is colored in red if one of the corresponding positions in the old tape is colored in red. Bob has already colored the tape, and Ben has proposed the positions to be folded. Please write a program to compute the expected lengths colored in red.

HBC224024矩阵,枚举,单调队列单调栈,数据结构ProblemB:Folding题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC224024矩阵 枚举 单调队列单调栈 数据结构ProblemB:Folding题解