首页 \ 问答 \ 有没有一种通用的方法来计算for循环的渐近时间复杂度?(Is there a general way to calculate the asymptotic time complexity of for loops with step?)

有没有一种通用的方法来计算for循环的渐近时间复杂度?(Is there a general way to calculate the asymptotic time complexity of for loops with step?)

是否有一般方法/方法/方法来计算此类循环的渐近时间复杂度?

j=a
while j<n do
    j=f(j)

其中f(j)可以是j+1 2*jj*j等。

请注意,上面的代码等同于C for循环

for (j=a; j<n; j=f(j));

Is there a general way/approach/methodology to calculate the asymptotic time complexity of such loops?

j=a
while j<n do
    j=f(j)

where f(j) could be j+1, 2*j, j*j etc..

Note that the above code is equivalent to the C for-loop

for (j=a; j<n; j=f(j));

原文:https://stackoverflow.com/questions/37645550
更新时间:2022-03-17 19:03

最满意答案

如果你想获得bytearray(b'\x01\x02xx')你需要使用bytearray对象的__repr__方法:

print repr(bytearray([1,2,120,120]))

默认情况下, __str__处于调用状态,返回字节数组的字符串表示形式。 该字符串包含不可打印字符的\x01\x02 ,因此您会看到问号。

参考文献:


If you want to get bytearray(b'\x01\x02xx') you need to use the __repr__ method of a bytearray object:

print repr(bytearray([1,2,120,120]))

By default __str__ in invoked, that returns a string representation of a byte array. And that string contains the \x01\x02 that are not printable characters, hence you see question marks.

References:

相关问答

更多
  • 1、Python数组的变量是不需要定义的,这方面和php一样,它比javascript还是宽松,不过它是用缩进作为段落标识的,作为习惯了C语言风格语法的人,可能一开始会很不习惯使用。   但细一想,其实也是很正常,很合理的。   2、虽然Python在面向过程/面向对象方面也是很宽松,但实际上一般的程序都是一个主入口。   3、然后不断调用其它类库或函数,所以用缩进的方式并无不妥,那样一方面要求用户写代码时要规范,另一方面反向省去了多余的{}。   4、与C语言风格相比,Python主要语法特点而下:    ...
  • 正如医生所说, 返回一个新的字节数组。 ...是0 <= x <256范围内的可变整数序列 例如, >>> s = 'hello world' >>> print bytearray(s) hello world >>> bytearray(s)[0] 104 104是ASCII的ASCII侧。 类bytearray的方法是reverse ,但string不是。 为了反转字符串,这段代码首先得到它的字节数组,然后保留,最后得到str的反向字符串。 此外,您可以使用[::-1]来反转字符串。 ...
  • 格式f适用于32位浮点数,需要使用d来表示64位浮点数(双精度)。 请参见格式字符 - struct 明确指定>以获得与站点相同的结果(big-endian) 使用binascii.hexlify将二进制字符串转换为十六进制表示形式。 >>> binascii.hexlify(struct.pack('>d', floats[0])) b'40091eb851eb851f' >>> import struct >>> import binascii >>> >>> floats = [3.14, 2.7, ...
  • Python bytearray是否在C表示中使用有符号整数? 它使用char 。 这些是否签名取决于编译器。 您可以在Include/bytearrayobject.h看到这一点。 这是2.7版本 : /* Object layout */ typedef struct { PyObject_VAR_HEAD /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */ int ob_exports; /* how many buffe ...
  • 因为2f是字符/的ASCII码。 Because 2f is the ASCII code for the character /.
  • 好吧,最后,在网络软件上工作,我发现了一个用于内存视图的用例:当我们有一个固定大小的套接字缓冲区并且我们想对它执行快速切片时(从任何给定位置读/写数据不创建额外的副本)在内存中),像这样: buf = bytearray(4096) mview = memoryview(buf) socket.recv_into(mview) print mview[256:] 所以,在某些情况下,在bytearray上有一个内存视图是很方便的。 这个方案唯一应该记住的是:在bytearray上创建一个内存视图后,你不能 ...
  • 传递sep=","作为print()的参数 你几乎在那里的印刷声明。 不需要循环, print有一个sep参数和end 。 >>> print(*range(5), sep=", ") 0, 1, 2, 3, 4 一点解释 内置print将任意数量的项目作为参数打印。 任何非关键字参数将被打印,由sep分隔。 sep的默认值是一个空格。 >>> print("hello", "world") hello world 改变sep有预期的结果。 >>> print("hello", "world", sep ...
  • 如果需要实际的bytearray对象,请将列表传递给bytearray构造函数。 serialCOM.write(bytearray(packet)) 请注意, unixTime不会转换为字符串,因此您必须先将其转换。 但你可能想要的(基于有关分号的注释)是使用字符串的join方法加入字符串,如下所示: # Force all items in the list to be strings msg = ';'.join(map(str,packet)) serialCOM.write(msg) 然后,加 ...
  • 如果变量是整数,则可以使用位移和按位或运算来形成由8位组成的值,然后将其存储在bytearray中的所需位置。 ba[i] = version << 6 | padding << 5 | extension << 4 | cc If the variables are integers, you can just use bit-shifts and bitwise-or operations to form a value comprised of 8-bits and then store that ...
  • 如果你想获得bytearray(b'\x01\x02xx')你需要使用bytearray对象的__repr__方法: print repr(bytearray([1,2,120,120])) 默认情况下, __str__处于调用状态,返回字节数组的字符串表示形式。 该字符串包含不可打印字符的\x01\x02 ,因此您会看到问号。 参考文献: https://docs.python.org/2/library/functions.html#repr If you want to get bytearray( ...

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)