小编Zei*_*nes的帖子

给定一个节点,刻录整个二叉树需要多长时间?

我在一次模拟采访中遇到了一个问题,我必须找到一个二进制树在一个给定节点已经着火后完全烧毁多久.

"从一个叶子节点开始刻录二进制树.从一个节点到另一个节点刻录的时间是多少?整个树被烧毁的时间是什么?火将从一个节点传播到所有路径. "

假设你有一棵这样的树,其中N是着火的节点.这发生在第一秒,其中秒是s,所以在第0秒:

           1
       /       \
      1          1
    /  \          \
   1    1          1
      /   \         \
     1     N         1
                      \
                       1
Run Code Online (Sandbox Code Playgroud)

经过一秒钟后,将使用更多刻录的节点更新树.下一秒(s + 1)的示例将如下所示:

           1
       /       \
      1          1
    /  \          \
   1    N          1
      /   \         \
     1     N         1
                      \
                       1
Run Code Online (Sandbox Code Playgroud)

下一秒(s + 2)的示例将是这样的:

           1
       /       \
      N          1
    /  \          \
   1    N          1
      /   \         \
     N     N         1
                      \
                       1  
Run Code Online (Sandbox Code Playgroud)

现在在第三秒(s + 3)将是这样的:

           N
       /       \
      N          1
    /  \          \
   N    N …
Run Code Online (Sandbox Code Playgroud)

algorithm recursion binary-tree class python-3.x

11
推荐指数
1
解决办法
3475
查看次数

除以负数让我在 NASM 中溢出

我正在自学一些使用 x86-64 Mac OS 的汇编编程。我试图弄清楚为什么在将正整数除以负整数时会溢出。例如,5/-2必须返回-2。但是,就我而言,它2147483371在我执行时返回 a-554/2而不是-277...这是我的程序集文件中的内容:

; compiling using: nasm -f macho64 -o divide.o divide.s
[bits 64]
global _divide
section .text

; int divide(int dividend, int divisor)
_divide:

    xor rdx, rdx        ; making this to 0
    push rbp            ; base stack pointer
    mov rax, rdi        ; dividend
    mov rcx, rsi        ; divisor
    idiv rcx            ; integer division

    add rsp, 8
    ret
Run Code Online (Sandbox Code Playgroud)

在我的main.c文件中,我有这个:

#include <stdio.h>
extern int divide(int dividend, …
Run Code Online (Sandbox Code Playgroud)

assembly x86-64 nasm

2
推荐指数
1
解决办法
1264
查看次数

标签 统计

algorithm ×1

assembly ×1

binary-tree ×1

class ×1

nasm ×1

python-3.x ×1

recursion ×1

x86-64 ×1