HBC223569[NOIP2000]单词接龙,字符串,深度优先搜索(DFS),搜索KeepCalmAndCarryOff题解 (外语:petra)

一个忧伤的美男子 算法基础篇 39 0
挑战自我,勇攀编程高峰!全网最全C++题库,助您成为编程达人。
Petra is learning how to add two positive integers in school, but thinks it is a bit too difficult. They are currently working with the standard algorithm for addition, where you first c

Petra is learning how to add two positive integers in school, but thinks it is a bit too difficult. They are currently working with the standard algorithm for addition, where you first compute the sum of the two units digits, then the sum of the two tens digits, and so on. Whenever the sum of the digits at the same position in the two numbers exceeds 9, a carry digit is added onto the digit of the next higher magnitude. Petra has trouble with the last step – she often forgets to keep track of the carry digit. A few weeks ago, she also learnt a simpler method of addition. In this method, you repeatedly add 1 to one of the numbers and subtract 1 from the other, until the second one reaches zero. This can of course take a lot of time for large numbers. Petra now wants to combine the two methods, for fast and error-free addition. Her plan is to first perform the second method one step at a time, until the two numbers would not produce a carry digit when added using the standard algorithm (for positive integers, this always happens eventually). To evaluate the performance of her new method, she has asked you to help her compute the number of steps she must perform of the second method when adding two given integers. Petra may perform the addition by 1 to either of the two numbers (and subtraction by 1 from the other).

HBC223569[NOIP2000]单词接龙,字符串,深度优先搜索(DFS),搜索KeepCalmAndCarryOff题解
(外语:petra)-第1张图片-东莞河马信息技术
(图片来源网络,侵删)

标签: HBC223569[NOIP2000]单词接龙 字符串 深度优先搜索(DFS) 搜索KeepCalmAndCarryOff题解