UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213367#2355. Digitwangyaxu12300ms0kbPython3703b2024-11-11 20:25:342024-11-11 23:03:59

answer

def a(n):
    queue = [(0, 0)]  # 用队列存储 (当前值, 加1操作次数) 的元组,初始为 (0, 0)
    visited = set()  # 用于记录已经访问过的数值,避免重复计算

    while queue:
        current_value, add_ones_count = queue.pop(0)

        if current_value % n == 0 and current_value > 0:
            return add_ones_count

        if current_value not in visited:
            visited.add(current_value)

            # 进行乘以10的操作
            queue.append((current_value * 10, add_ones_count))

            # 进行加1的操作
            queue.append((current_value + 1, add_ones_count + 1))
result = a(216)
print("a(3)的值为:", result)

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Dangerous Syscalls

input:

81920

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

55966

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

92661

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

68013

output:


result:


Test #5:

score: 0
Dangerous Syscalls

input:

72927

output:


result:


Test #6:

score: 0
Dangerous Syscalls

input:

15047

output:


result:


Test #7:

score: 0
Dangerous Syscalls

input:

59994

output:


result:


Test #8:

score: 0
Dangerous Syscalls

input:

97273

output:


result:


Test #9:

score: 0
Dangerous Syscalls

input:

51139

output:


result:


Test #10:

score: 0
Dangerous Syscalls

input:

55788

output:


result: