bai-python-hwc 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. bai_python_hwc/__init__.py +46 -0
  2. bai_python_hwc/answers/hwc101.py +38 -0
  3. bai_python_hwc/answers/hwc103.py +52 -0
  4. bai_python_hwc/answers/hwc104.py +45 -0
  5. bai_python_hwc/answers/hwc105.py +45 -0
  6. bai_python_hwc/answers/hwc106.py +56 -0
  7. bai_python_hwc/answers/hwc107.py +49 -0
  8. bai_python_hwc/answers/hwc108.py +45 -0
  9. bai_python_hwc/answers/hwc109.py +50 -0
  10. bai_python_hwc/answers/hwc110.py +42 -0
  11. bai_python_hwc/answers/hwc111.py +47 -0
  12. bai_python_hwc/answers/hwc112.py +42 -0
  13. bai_python_hwc/answers/hwc113.py +58 -0
  14. bai_python_hwc/answers/hwc114.py +58 -0
  15. bai_python_hwc/answers/hwc115.py +38 -0
  16. bai_python_hwc/answers/hwc116.py +44 -0
  17. bai_python_hwc/answers/hwc117.py +46 -0
  18. bai_python_hwc/answers/hwc118.py +47 -0
  19. bai_python_hwc/answers/hwc119.py +44 -0
  20. bai_python_hwc/answers/hwc120.py +41 -0
  21. bai_python_hwc/answers/hwc121.py +50 -0
  22. bai_python_hwc/answers/hwc122.py +54 -0
  23. bai_python_hwc/answers/hwc123.py +43 -0
  24. bai_python_hwc/answers/hwc124.py +41 -0
  25. bai_python_hwc/answers/hwc125.py +52 -0
  26. bai_python_hwc/answers/hwc126.py +40 -0
  27. bai_python_hwc/answers/hwc127.py +41 -0
  28. bai_python_hwc/answers/hwc128.py +39 -0
  29. bai_python_hwc/answers/hwc130.py +46 -0
  30. bai_python_hwc/answers/hwc131.py +46 -0
  31. bai_python_hwc/answers/hwc132.py +38 -0
  32. bai_python_hwc/answers/hwc133.py +61 -0
  33. bai_python_hwc/answers/hwc134.py +45 -0
  34. bai_python_hwc/answers/hwc135.py +49 -0
  35. bai_python_hwc/answers/hwc136.py +43 -0
  36. bai_python_hwc/answers/hwc201.py +47 -0
  37. bai_python_hwc/answers/hwc202.py +47 -0
  38. bai_python_hwc/answers/hwc203.py +48 -0
  39. bai_python_hwc/answers/hwc204.py +61 -0
  40. bai_python_hwc/answers/hwc205.py +56 -0
  41. bai_python_hwc/answers/hwc206.py +53 -0
  42. bai_python_hwc/answers/hwc207.py +43 -0
  43. bai_python_hwc/answers/hwc208.py +57 -0
  44. bai_python_hwc/answers/hwc209.py +42 -0
  45. bai_python_hwc/answers/hwc210.py +46 -0
  46. bai_python_hwc/answers/hwc211.py +62 -0
  47. bai_python_hwc/answers/hwc212.py +58 -0
  48. bai_python_hwc/answers/hwc213.py +54 -0
  49. bai_python_hwc/answers/hwc214.py +55 -0
  50. bai_python_hwc/answers/hwc215.py +53 -0
  51. bai_python_hwc/answers/hwc216.py +50 -0
  52. bai_python_hwc/answers/hwc217.py +38 -0
  53. bai_python_hwc/answers/hwc218.py +44 -0
  54. bai_python_hwc/answers/hwc219.py +49 -0
  55. bai_python_hwc/answers/hwc220.py +58 -0
  56. bai_python_hwc/answers/hwc221.py +49 -0
  57. bai_python_hwc/answers/hwc222.py +48 -0
  58. bai_python_hwc/answers/hwc223.py +39 -0
  59. bai_python_hwc/answers/hwc224.py +47 -0
  60. bai_python_hwc/answers/hwc225.py +50 -0
  61. bai_python_hwc/answers/hwc226.py +41 -0
  62. bai_python_hwc/answers/hwc227.py +40 -0
  63. bai_python_hwc/answers/hwc228.py +41 -0
  64. bai_python_hwc/answers/hwc229.py +51 -0
  65. bai_python_hwc/answers/hwc230.py +41 -0
  66. bai_python_hwc/answers/hwc231.py +39 -0
  67. bai_python_hwc/answers/hwc232.py +44 -0
  68. bai_python_hwc/answers/hwc233.py +49 -0
  69. bai_python_hwc/answers/hwc234.py +52 -0
  70. bai_python_hwc/answers/hwc235.py +45 -0
  71. bai_python_hwc/answers/hwc236.py +53 -0
  72. bai_python_hwc/answers/hwc237.py +56 -0
  73. bai_python_hwc/answers/hwc238.py +52 -0
  74. bai_python_hwc/answers/hwc239.py +60 -0
  75. bai_python_hwc/answers/hwc240.py +45 -0
  76. bai_python_hwc/answers/hwc241.py +48 -0
  77. bai_python_hwc/answers/hwc242.py +50 -0
  78. bai_python_hwc/answers/hwc243.py +61 -0
  79. bai_python_hwc/answers/hwc244.py +61 -0
  80. bai_python_hwc/answers/hwc245.py +47 -0
  81. bai_python_hwc/answers/hwc246.py +52 -0
  82. bai_python_hwc/answers/hwc247.py +76 -0
  83. bai_python_hwc/answers/hwc301.py +44 -0
  84. bai_python_hwc/answers/hwc302.py +53 -0
  85. bai_python_hwc/answers/hwc303.py +63 -0
  86. bai_python_hwc/answers/hwc304.py +56 -0
  87. bai_python_hwc/answers/hwc305.py +59 -0
  88. bai_python_hwc/answers/hwc306.py +60 -0
  89. bai_python_hwc/answers/hwc307.py +50 -0
  90. bai_python_hwc/answers/hwc308.py +59 -0
  91. bai_python_hwc/answers/hwc309.py +48 -0
  92. bai_python_hwc/answers/hwc310.py +38 -0
  93. bai_python_hwc/answers/hwc311.py +48 -0
  94. bai_python_hwc/answers/hwc312.py +49 -0
  95. bai_python_hwc/answers/hwc313.py +54 -0
  96. bai_python_hwc/answers/hwc314.py +49 -0
  97. bai_python_hwc/answers/hwc315.py +63 -0
  98. bai_python_hwc/answers/hwc316.py +65 -0
  99. bai_python_hwc/answers/hwc317.py +57 -0
  100. bai_python_hwc/answers/hwc318.py +55 -0
  101. bai_python_hwc/answers/hwc319.py +50 -0
  102. bai_python_hwc/answers/hwc320.py +84 -0
  103. bai_python_hwc/answers/hwc321.py +49 -0
  104. bai_python_hwc/answers/hwc322.py +49 -0
  105. bai_python_hwc/answers/hwc323.py +69 -0
  106. bai_python_hwc/answers/hwc324.py +66 -0
  107. bai_python_hwc/answers/hwc325.py +49 -0
  108. bai_python_hwc/answers/hwc326.py +53 -0
  109. bai_python_hwc/answers/hwc327.py +38 -0
  110. bai_python_hwc/answers/hwc328.py +50 -0
  111. bai_python_hwc/answers/hwc329.py +59 -0
  112. bai_python_hwc/answers/hwc330.py +45 -0
  113. bai_python_hwc/answers/hwc332.py +57 -0
  114. bai_python_hwc/answers/hwc401.py +50 -0
  115. bai_python_hwc/answers/hwc402.py +43 -0
  116. bai_python_hwc/answers/hwc403.py +73 -0
  117. bai_python_hwc/answers/hwc404.py +51 -0
  118. bai_python_hwc/answers/hwc405.py +62 -0
  119. bai_python_hwc/answers/hwc406.py +66 -0
  120. bai_python_hwc/answers/hwc407.py +49 -0
  121. bai_python_hwc/answers/hwc408.py +67 -0
  122. bai_python_hwc/answers/hwc409.py +51 -0
  123. bai_python_hwc/answers/hwc410.py +52 -0
  124. bai_python_hwc/answers/hwc411.py +57 -0
  125. bai_python_hwc/answers/hwc412.py +53 -0
  126. bai_python_hwc/answers/hwc413.py +65 -0
  127. bai_python_hwc/answers/hwc414.py +50 -0
  128. bai_python_hwc/answers/hwc415.py +61 -0
  129. bai_python_hwc/answers/hwc416.py +69 -0
  130. bai_python_hwc/answers/hwc418.py +47 -0
  131. bai_python_hwc/answers/hwc419.py +62 -0
  132. bai_python_hwc/answers/hwc421.py +51 -0
  133. bai_python_hwc/answers/hwc424.py +48 -0
  134. bai_python_hwc/answers/hwc501.py +63 -0
  135. bai_python_hwc/answers/hwc502.py +69 -0
  136. bai_python_hwc/answers/hwc503.py +75 -0
  137. bai_python_hwc/answers/hwc504.py +52 -0
  138. bai_python_hwc/answers/hwc505.py +63 -0
  139. bai_python_hwc/answers/hwc506.py +61 -0
  140. bai_python_hwc/answers/hwc508.py +60 -0
  141. bai_python_hwc/answers/hwc509.py +85 -0
  142. bai_python_hwc/answers/hwc510.py +56 -0
  143. bai_python_hwc/answers/hwc511.py +52 -0
  144. bai_python_hwc/answers/hwc513.py +63 -0
  145. bai_python_hwc/answers/hwc514.py +74 -0
  146. bai_python_hwc/answers/hwc515.py +83 -0
  147. bai_python_hwc/answers/hwc516.py +67 -0
  148. bai_python_hwc/answers/hwc517.py +46 -0
  149. bai_python_hwc/answers/hwc520.py +54 -0
  150. bai_python_hwc/answers/hwc526.py +58 -0
  151. bai_python_hwc/attachments/hwc424.pdf +0 -0
  152. bai_python_hwc/attachments/hwc501.pdf +0 -0
  153. bai_python_hwc/questions/hwc101.txt +17 -0
  154. bai_python_hwc/questions/hwc103.txt +27 -0
  155. bai_python_hwc/questions/hwc104.txt +22 -0
  156. bai_python_hwc/questions/hwc105.txt +23 -0
  157. bai_python_hwc/questions/hwc106.txt +26 -0
  158. bai_python_hwc/questions/hwc107.txt +29 -0
  159. bai_python_hwc/questions/hwc108.txt +18 -0
  160. bai_python_hwc/questions/hwc109.txt +24 -0
  161. bai_python_hwc/questions/hwc110.txt +16 -0
  162. bai_python_hwc/questions/hwc111.txt +25 -0
  163. bai_python_hwc/questions/hwc112.txt +13 -0
  164. bai_python_hwc/questions/hwc113.txt +28 -0
  165. bai_python_hwc/questions/hwc114.txt +35 -0
  166. bai_python_hwc/questions/hwc115.txt +15 -0
  167. bai_python_hwc/questions/hwc116.txt +13 -0
  168. bai_python_hwc/questions/hwc117.txt +14 -0
  169. bai_python_hwc/questions/hwc118.txt +25 -0
  170. bai_python_hwc/questions/hwc119.txt +18 -0
  171. bai_python_hwc/questions/hwc120.txt +23 -0
  172. bai_python_hwc/questions/hwc121.txt +26 -0
  173. bai_python_hwc/questions/hwc122.txt +21 -0
  174. bai_python_hwc/questions/hwc123.txt +21 -0
  175. bai_python_hwc/questions/hwc124.txt +19 -0
  176. bai_python_hwc/questions/hwc125.txt +31 -0
  177. bai_python_hwc/questions/hwc126.txt +18 -0
  178. bai_python_hwc/questions/hwc127.txt +17 -0
  179. bai_python_hwc/questions/hwc128.txt +14 -0
  180. bai_python_hwc/questions/hwc130.txt +23 -0
  181. bai_python_hwc/questions/hwc131.txt +19 -0
  182. bai_python_hwc/questions/hwc132.txt +16 -0
  183. bai_python_hwc/questions/hwc133.txt +39 -0
  184. bai_python_hwc/questions/hwc134.txt +22 -0
  185. bai_python_hwc/questions/hwc135.txt +29 -0
  186. bai_python_hwc/questions/hwc136.txt +20 -0
  187. bai_python_hwc/questions/hwc201.txt +20 -0
  188. bai_python_hwc/questions/hwc202.txt +25 -0
  189. bai_python_hwc/questions/hwc203.txt +26 -0
  190. bai_python_hwc/questions/hwc204.txt +32 -0
  191. bai_python_hwc/questions/hwc205.txt +28 -0
  192. bai_python_hwc/questions/hwc206.txt +28 -0
  193. bai_python_hwc/questions/hwc207.txt +16 -0
  194. bai_python_hwc/questions/hwc208.txt +27 -0
  195. bai_python_hwc/questions/hwc209.txt +15 -0
  196. bai_python_hwc/questions/hwc210.txt +28 -0
  197. bai_python_hwc/questions/hwc211.txt +35 -0
  198. bai_python_hwc/questions/hwc212.txt +29 -0
  199. bai_python_hwc/questions/hwc213.txt +27 -0
  200. bai_python_hwc/questions/hwc214.txt +27 -0
  201. bai_python_hwc/questions/hwc215.txt +28 -0
  202. bai_python_hwc/questions/hwc216.txt +22 -0
  203. bai_python_hwc/questions/hwc217.txt +17 -0
  204. bai_python_hwc/questions/hwc218.txt +18 -0
  205. bai_python_hwc/questions/hwc219.txt +22 -0
  206. bai_python_hwc/questions/hwc220.txt +28 -0
  207. bai_python_hwc/questions/hwc221.txt +18 -0
  208. bai_python_hwc/questions/hwc222.txt +20 -0
  209. bai_python_hwc/questions/hwc223.txt +18 -0
  210. bai_python_hwc/questions/hwc224.txt +23 -0
  211. bai_python_hwc/questions/hwc225.txt +26 -0
  212. bai_python_hwc/questions/hwc226.txt +18 -0
  213. bai_python_hwc/questions/hwc227.txt +15 -0
  214. bai_python_hwc/questions/hwc228.txt +16 -0
  215. bai_python_hwc/questions/hwc229.txt +20 -0
  216. bai_python_hwc/questions/hwc230.txt +18 -0
  217. bai_python_hwc/questions/hwc231.txt +13 -0
  218. bai_python_hwc/questions/hwc232.txt +19 -0
  219. bai_python_hwc/questions/hwc233.txt +21 -0
  220. bai_python_hwc/questions/hwc234.txt +27 -0
  221. bai_python_hwc/questions/hwc235.txt +18 -0
  222. bai_python_hwc/questions/hwc236.txt +23 -0
  223. bai_python_hwc/questions/hwc237.txt +28 -0
  224. bai_python_hwc/questions/hwc238.txt +25 -0
  225. bai_python_hwc/questions/hwc239.txt +28 -0
  226. bai_python_hwc/questions/hwc240.txt +21 -0
  227. bai_python_hwc/questions/hwc241.txt +25 -0
  228. bai_python_hwc/questions/hwc242.txt +23 -0
  229. bai_python_hwc/questions/hwc243.txt +35 -0
  230. bai_python_hwc/questions/hwc244.txt +25 -0
  231. bai_python_hwc/questions/hwc245.txt +24 -0
  232. bai_python_hwc/questions/hwc246.txt +28 -0
  233. bai_python_hwc/questions/hwc247.txt +51 -0
  234. bai_python_hwc/questions/hwc301.txt +23 -0
  235. bai_python_hwc/questions/hwc302.txt +26 -0
  236. bai_python_hwc/questions/hwc303.txt +32 -0
  237. bai_python_hwc/questions/hwc304.txt +32 -0
  238. bai_python_hwc/questions/hwc305.txt +31 -0
  239. bai_python_hwc/questions/hwc306.txt +31 -0
  240. bai_python_hwc/questions/hwc307.txt +29 -0
  241. bai_python_hwc/questions/hwc308.txt +30 -0
  242. bai_python_hwc/questions/hwc309.txt +25 -0
  243. bai_python_hwc/questions/hwc310.txt +15 -0
  244. bai_python_hwc/questions/hwc311.txt +23 -0
  245. bai_python_hwc/questions/hwc312.txt +19 -0
  246. bai_python_hwc/questions/hwc313.txt +26 -0
  247. bai_python_hwc/questions/hwc314.txt +27 -0
  248. bai_python_hwc/questions/hwc315.txt +21 -0
  249. bai_python_hwc/questions/hwc316.txt +36 -0
  250. bai_python_hwc/questions/hwc317.txt +28 -0
  251. bai_python_hwc/questions/hwc318.txt +27 -0
  252. bai_python_hwc/questions/hwc319.txt +26 -0
  253. bai_python_hwc/questions/hwc320.txt +42 -0
  254. bai_python_hwc/questions/hwc321.txt +27 -0
  255. bai_python_hwc/questions/hwc322.txt +26 -0
  256. bai_python_hwc/questions/hwc323.txt +24 -0
  257. bai_python_hwc/questions/hwc324.txt +40 -0
  258. bai_python_hwc/questions/hwc325.txt +21 -0
  259. bai_python_hwc/questions/hwc326.txt +25 -0
  260. bai_python_hwc/questions/hwc327.txt +16 -0
  261. bai_python_hwc/questions/hwc328.txt +15 -0
  262. bai_python_hwc/questions/hwc329.txt +26 -0
  263. bai_python_hwc/questions/hwc330.txt +27 -0
  264. bai_python_hwc/questions/hwc332.txt +26 -0
  265. bai_python_hwc/questions/hwc401.txt +25 -0
  266. bai_python_hwc/questions/hwc402.txt +24 -0
  267. bai_python_hwc/questions/hwc403.txt +37 -0
  268. bai_python_hwc/questions/hwc404.txt +23 -0
  269. bai_python_hwc/questions/hwc405.txt +29 -0
  270. bai_python_hwc/questions/hwc406.txt +34 -0
  271. bai_python_hwc/questions/hwc407.txt +24 -0
  272. bai_python_hwc/questions/hwc408.txt +28 -0
  273. bai_python_hwc/questions/hwc409.txt +25 -0
  274. bai_python_hwc/questions/hwc410.txt +23 -0
  275. bai_python_hwc/questions/hwc411.txt +34 -0
  276. bai_python_hwc/questions/hwc412.txt +29 -0
  277. bai_python_hwc/questions/hwc413.txt +28 -0
  278. bai_python_hwc/questions/hwc414.txt +27 -0
  279. bai_python_hwc/questions/hwc415.txt +27 -0
  280. bai_python_hwc/questions/hwc416.txt +36 -0
  281. bai_python_hwc/questions/hwc418.txt +25 -0
  282. bai_python_hwc/questions/hwc419.txt +28 -0
  283. bai_python_hwc/questions/hwc421.txt +23 -0
  284. bai_python_hwc/questions/hwc424.txt +20 -0
  285. bai_python_hwc/questions/hwc501.txt +23 -0
  286. bai_python_hwc/questions/hwc502.txt +41 -0
  287. bai_python_hwc/questions/hwc503.txt +36 -0
  288. bai_python_hwc/questions/hwc504.txt +18 -0
  289. bai_python_hwc/questions/hwc505.txt +25 -0
  290. bai_python_hwc/questions/hwc506.txt +32 -0
  291. bai_python_hwc/questions/hwc508.txt +24 -0
  292. bai_python_hwc/questions/hwc509.txt +42 -0
  293. bai_python_hwc/questions/hwc510.txt +25 -0
  294. bai_python_hwc/questions/hwc511.txt +23 -0
  295. bai_python_hwc/questions/hwc513.txt +25 -0
  296. bai_python_hwc/questions/hwc514.txt +35 -0
  297. bai_python_hwc/questions/hwc515.txt +46 -0
  298. bai_python_hwc/questions/hwc516.txt +26 -0
  299. bai_python_hwc/questions/hwc517.txt +20 -0
  300. bai_python_hwc/questions/hwc520.txt +27 -0
  301. bai_python_hwc/questions/hwc526.txt +36 -0
  302. bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
  303. bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
  304. bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
  305. bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,44 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 你是一个专业的小偷,计划偷窃沿街的房屋。
16
+ 每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,
17
+ 如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。
18
+ 给定一个代表每个房屋存放金额的非负整数数组,
19
+ 计算你不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。
20
+
21
+ 示例 1:
22
+
23
+ 输入: [1,2,3,1]
24
+ 输出: 4
25
+ 解释: 偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。偷窃到的最高金额 = 1 + 3 = 4 。
26
+ '''
27
+
28
+ # 参考答案
29
+ def TEST_DO_NOT_CHANGE(nums):
30
+ rlt=None
31
+ ##########start下面可以改动
32
+
33
+ previous = rlt = 0
34
+ for value in nums:
35
+ previous, rlt = rlt, max(rlt, previous + value)
36
+
37
+ ##########end上面可以改动
38
+ return rlt
39
+
40
+ if __name__ == "__main__":
41
+ ###########下面可以修改
42
+ print(TEST_DO_NOT_CHANGE([1,2,3,1])) # 答案应该是4
43
+ print(TEST_DO_NOT_CHANGE([2,7,9,3,1])) # 答案应该是12
44
+ print(TEST_DO_NOT_CHANGE([2,1,1,2])) # 答案应该是4
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:数组列表中的最大距离
15
+ 给定m个数组,每个数组都已经按照升序排好序了。
16
+ 现在你需要从两个不同的数组中选择两个整数(每个数组选一个)并且计算它们的距离。两个整数a和b之间的距离定义为它们差的绝对值|a-b|。
17
+ 返回最大距离。
18
+
19
+ 示例:
20
+ 输入:[[1,2,3],[4,5],[1,2,3]]输出:4解释:一种得到答案 4 的方法是从第一个数组或者第三个数组中选择 1,同时从第二个数组中选择 5 。
21
+
22
+ 提示:
23
+ m == arrays.length
24
+ 2 <= m <= 10^5
25
+ 1 <= arrays[i].length <= 500
26
+ -10^4 <= arrays[i][j] <= 10^4
27
+ arrays[i]以升序排序。
28
+ 所有数组中最多有 10^5 个整数。
29
+ '''
30
+
31
+ # 参考答案
32
+
33
+ def TEST_DO_NOT_CHANGE(num):
34
+ result =None
35
+ ##########start下面可以改动
36
+
37
+ low, high = num[0][0], num[0][-1]
38
+ result = 0
39
+ for i in range(1, len(num)):
40
+ row = num[i]
41
+ result = max(result, row[-1] - low, high - row[0])
42
+ low, high = min(low, row[0]), max(high, row[-1])
43
+
44
+ ##########end上面可以改动
45
+ return result
46
+
47
+ if __name__ == "__main__":
48
+ ###########下面可以修改
49
+ print(TEST_DO_NOT_CHANGE([
50
+ [1, 2, 3],
51
+ [4,5],
52
+ [1, 2, 3],
53
+ ]))
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:检查一个字符串是否包含所有长度为 k 的二进制子串
15
+
16
+ 给你一个二进制字符串 s 和一个整数 k 。如果所有长度为 k 的二进制字符串都是 s 的子串,请返回 True ,否则请返回 False 。
17
+
18
+ 示例 1:
19
+
20
+ 输入:s = "00110110", k = 2
21
+ 输出:True
22
+ 解释:长度为 2 的二进制串包括 "00","01","10" 和 "11"。它们分别是 s 中下标为 0,1,3,2 开始的长度为 2 的子串。
23
+
24
+ 示例 2:
25
+
26
+ 输入:s = "0110", k = 1
27
+ 输出:True
28
+ 解释:长度为 1 的二进制串包括 "0" 和 "1",显然它们都是 s 的子串。
29
+
30
+ 示例 3:
31
+
32
+ 输入:s = "0110", k = 2
33
+ 输出:False
34
+ 解释:长度为 2 的二进制串 "00" 没有出现在 s 中。
35
+ '''
36
+
37
+ # 参考答案
38
+ def TEST_DO_NOT_CHANGE(s,k):
39
+ rlt = None
40
+ ##########start下面可以改动
41
+
42
+ windows = len(s) - k + 1
43
+ rlt = False
44
+ if windows > 0 and k < windows.bit_length():
45
+ required = 1 << k
46
+ seen = set()
47
+ code = 0
48
+ for i, char in enumerate(s):
49
+ code = ((code << 1) | int(char)) & (required - 1)
50
+ if i >= k - 1:
51
+ seen.add(code)
52
+ if len(seen) == required:
53
+ rlt = True
54
+ break
55
+
56
+ ##########end上面可以改动
57
+ return rlt
58
+
59
+ if __name__ == "__main__":
60
+ ###########下面可以修改
61
+ print(TEST_DO_NOT_CHANGE("00110110",2))
62
+ print(TEST_DO_NOT_CHANGE("0110",1))
63
+ print(TEST_DO_NOT_CHANGE("0110",2))
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:重排数组以得到最大前缀分数
15
+
16
+ 给你一个整数数组 nums 。你可以将 nums 中的元素按 任意顺序 重新排列。
17
+ 排好后从头开始累加:第 1 个数、前 2 个数之和、前 3 个数之和……这些累加结果叫"前缀和"。
18
+ 每得到一个 正数 的前缀和就记 1 分(前缀和为 0 或负数不得分)。
19
+
20
+ 请你返回最多能得到多少分。
21
+
22
+ 示例 1:
23
+
24
+ 输入:nums = [2,-1,0,1,-3,3,-3]
25
+ 输出:6
26
+ 解释:数组重排为 nums = [2,3,1,-1,-3,0,-3] 。
27
+ prefix = [2,5,6,5,2,2,-1] ,分数为 6 。
28
+ 可以证明 6 是能够得到的最大分数。
29
+
30
+ 示例 2:
31
+
32
+ 输入:nums = [-2,-3,0]
33
+ 输出:0
34
+ 解释:不管怎么重排数组得到的分数都是 0 。
35
+ '''
36
+
37
+ # 参考答案
38
+ def TEST_DO_NOT_CHANGE(nums):
39
+ result = None
40
+ ##########start下面可以改动
41
+
42
+ total = result = 0
43
+ for value in sorted(nums, reverse=True):
44
+ total += value
45
+ if total <= 0:
46
+ break
47
+ result += 1
48
+
49
+ ##########end上面可以改动
50
+ return result
51
+
52
+
53
+ if __name__ == "__main__":
54
+ ###########下面可以修改
55
+ print(TEST_DO_NOT_CHANGE([2,-1,0,1,-3,3,-3]))
56
+ print(TEST_DO_NOT_CHANGE([-2,-3,0]))
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给定一个含有n个正整数的数组和一个正整数 target 。
16
+ 找出该数组中满足"元素之和 ≥ target"的 连续子数组(即连续的一段)中长度最小的那个,并返回它的长度。
17
+ 如果不存在符合条件的子数组,返回 0 。
18
+
19
+ 示例 1:
20
+
21
+ 输入:target = 7, nums = [2,3,1,2,4,3]
22
+ 输出:2
23
+ 解释:子数组[4,3]是该条件下的长度最小的子数组。
24
+
25
+ 示例 2:
26
+
27
+ 输入:target = 4, nums = [1,4,4]
28
+ 输出:1
29
+
30
+ 示例 3:
31
+
32
+ 输入:target = 11, nums = [1,1,1,1,1,1,1,1]
33
+ 输出:0
34
+ '''
35
+
36
+ # 参考答案
37
+ def TEST_DO_NOT_CHANGE(target,nums):
38
+ rlt = None
39
+ ##########start下面可以改动
40
+
41
+ left = total = 0
42
+ best = len(nums) + 1
43
+ for right, value in enumerate(nums):
44
+ total += value
45
+ while total >= target:
46
+ best = min(best, right - left + 1)
47
+ total -= nums[left]
48
+ left += 1
49
+ rlt = best if best <= len(nums) else 0
50
+
51
+ ##########end上面可以改动
52
+ return rlt
53
+
54
+
55
+ if __name__ == "__main__":
56
+ ###########下面可以修改
57
+ print(TEST_DO_NOT_CHANGE(7,[2,3,1,2,4,3]))
58
+ print(TEST_DO_NOT_CHANGE(4,[1,4,4]))
59
+ print(TEST_DO_NOT_CHANGE(11,[1,1,1,1,1,1,1,1]))
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目: 汉明距离总和
15
+
16
+ 定义,两个整数的 汉明距离 指的是这两个数字的二进制数对应位不同的数量。
17
+
18
+ 给你一个整数数组 nums,请你计算并返回 nums 中任意两个数之间 汉明距离的总和 。
19
+
20
+ 提示:求4的二进制 bin(4) ,结果是字符串 '0b100'
21
+
22
+ 示例 1:
23
+
24
+ 输入:nums = [4,14,2]
25
+ 输出:6
26
+ 解释:在二进制表示中,4 表示为 0100 ,14 表示为 1110 ,2表示为 0010 。(这样表示是为了体现后四位之间关系)
27
+ 所以答案为:
28
+ HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6
29
+
30
+ 示例 2:
31
+
32
+ 输入:nums = [4,14,4]
33
+ 输出:4
34
+ '''
35
+
36
+ # 参考答案
37
+ def TEST_DO_NOT_CHANGE(nums):
38
+ rlt = None
39
+ ##########start下面可以改动
40
+
41
+ # 若有负数,采用可以共同容纳所有输入的最短补码宽度。
42
+ width = max((value.bit_length() for value in nums), default=0)
43
+ if any(value < 0 for value in nums):
44
+ width = max(
45
+ value.bit_length() + 1 if value >= 0 else (~value).bit_length() + 1
46
+ for value in nums
47
+ )
48
+ rlt = 0
49
+ for bit in range(width):
50
+ ones = sum((value >> bit) & 1 for value in nums)
51
+ rlt += ones * (len(nums) - ones)
52
+
53
+ ##########end上面可以改动
54
+ return rlt
55
+
56
+ if __name__ == "__main__":
57
+ ###########下面可以修改
58
+ nums = [4,14,2]
59
+ print(TEST_DO_NOT_CHANGE(nums))
60
+ print(TEST_DO_NOT_CHANGE([4,14,4])) # 示例 2,应输出 4
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:前K个高频元素
15
+
16
+ 给你一个整数数组 nums 和一个整数 k ,请你返回其中出现频率前 k 高的元素。
17
+ 频率相同的元素,你可以按 任意顺序 加入list。
18
+
19
+ 示例 1:
20
+
21
+ 输入: nums = [1,1,1,2,2,3], k = 2
22
+ 输出: [1,2]
23
+
24
+ 示例 2:
25
+
26
+ 输入: nums = [1], k = 1
27
+ 输出: [1]
28
+
29
+ 提示:
30
+ 1.k 的取值范围是 [1, 数组中不相同的元素的个数]
31
+ 2.当多个元素频率相同时,允许按任意顺序返回这些并列元素;测试数据会避免影响前 k 个集合的并列情况。
32
+ '''
33
+
34
+ # 参考答案
35
+ def TEST_DO_NOT_CHANGE(nums,k):
36
+ lst_rlt = []
37
+ ##########start下面可以改动
38
+
39
+ from collections import Counter
40
+
41
+ lst_rlt = [value for value, _ in Counter(nums).most_common(k)]
42
+
43
+ ##########end上面可以改动
44
+ return lst_rlt
45
+
46
+ if __name__ == "__main__":
47
+ ###########下面可以修改
48
+ nums = [1,1,1,2,2,3]
49
+ k = 2
50
+ print(TEST_DO_NOT_CHANGE(nums,k)) # 应该输出 [1, 2]
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。
16
+ 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。
17
+
18
+ 示例 1:
19
+
20
+ 输入:nums = [10,9,2,5,3,7,101,18]
21
+ 输出:4
22
+ 解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
23
+
24
+ 示例 2:
25
+
26
+ 输入:nums = [0,1,0,3,2,3]
27
+ 输出:4
28
+
29
+ 示例 3:
30
+
31
+ 输入:nums = [7,7,7,7,7,7,7]
32
+ 输出:1
33
+ '''
34
+
35
+ # 参考答案
36
+ def TEST_DO_NOT_CHANGE(nums):
37
+ rlt = None
38
+ ##########start下面可以改动
39
+
40
+ from bisect import bisect_left
41
+
42
+ # tails[i] 是长度 i + 1 的递增子序列所能达到的最小结尾。
43
+ tails = []
44
+ for value in nums:
45
+ i = bisect_left(tails, value)
46
+ if i == len(tails):
47
+ tails.append(value)
48
+ else:
49
+ tails[i] = value
50
+ rlt = len(tails)
51
+
52
+ ##########end上面可以改动
53
+ return rlt
54
+
55
+ if __name__ == "__main__":
56
+ ###########下面可以修改
57
+ print(TEST_DO_NOT_CHANGE([10,9,2,5,3,7,101,18]))
58
+ print(TEST_DO_NOT_CHANGE([0,1,0,3,2,3]))
59
+ print(TEST_DO_NOT_CHANGE([7,7,7,7,7,7,7]))
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目: 统计各位数字都不同的数字个数
15
+
16
+ 提示:
17
+ 给你一个整数 n ,统计并返回各位数字都不同的数字 x 的个数,其中 0 <= x < 10^n 。
18
+
19
+ 示例 1:
20
+
21
+ 输入:n = 2
22
+ 输出:91
23
+ 解释:答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。
24
+
25
+ 示例 2:
26
+ 输入:n = 0
27
+ 输出:1
28
+ '''
29
+
30
+ # 参考答案
31
+ def TEST_DO_NOT_CHANGE(n):
32
+ rlt = None
33
+ ##########start下面可以改动
34
+
35
+ rlt = 1 # 单独计入 0。
36
+ count = 9
37
+ for length in range(1, min(n, 10) + 1):
38
+ rlt += count
39
+ count *= 10 - length
40
+
41
+ ##########end上面可以改动
42
+ return rlt
43
+
44
+ if __name__ == "__main__":
45
+ ###########下面可以修改
46
+ n = 2
47
+ print(TEST_DO_NOT_CHANGE(n)) # 应该输出 91
48
+ # 题号:hwc309
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 一个机器人位于一个 m x n 网格的左上角,机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角,
16
+ 问总共有多少条不同的路径?,请在结果中只输出路径的个数,如3*4的网格,有10种路径,则输出: 10
17
+ 分别求出m=3,n=4时的路径数,m=5,n=6时的路径数,m=6,n=7时的路径数。
18
+ '''
19
+
20
+ # 参考答案
21
+
22
+ def TEST_DO_NOT_CHANGE(m, n):
23
+ result = None
24
+
25
+ ##########start下面可以改动
26
+
27
+ from math import comb
28
+
29
+ result = comb(m + n - 2, m - 1)
30
+
31
+ ##########end上面可以改动
32
+ return result
33
+ if __name__ == "__main__":
34
+ ###########下面可以修改
35
+
36
+ print(TEST_DO_NOT_CHANGE(3, 4))
37
+ print(TEST_DO_NOT_CHANGE(5, 6))
38
+ print(TEST_DO_NOT_CHANGE(6, 7))
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:
15
+ 现有两个没有重复元素的数组nums1和nums2,其中nums1是nums2的子集。
16
+
17
+ 请你找出nums1中每个元素在nums2中的下一个比其大的值。
18
+
19
+ nums1中数字x的下一个更大元素是指x在nums2中对应位置的右边的第一个比x大的元素。如果不存在,对应位置输出 -1 。
20
+ 输入: nums1 = [4,1,2], nums2 = [1,3,4,2].
21
+ 输出: [-1,3,-1]
22
+ 解释:
23
+ 对于nums1中的数字4 ,你无法在第二个数组中找到下一个更大的数字,因此输出 -1 。
24
+ 对于num1中的数字1 ,第二个数组中数字1右边的下一个较大数字是 3 。
25
+ 对于num1中的数字2 ,第二个数组中没有下一个更大的数字,因此输出 -1 。
26
+ '''
27
+
28
+ # 参考答案
29
+ def TEST_DO_NOT_CHANGE( nums1, nums2):
30
+ print(nums1, nums2)
31
+ lst_rlt = []
32
+ ##########start下面可以改动
33
+
34
+ greater = {}
35
+ stack = []
36
+ for value in nums2:
37
+ while stack and stack[-1] < value:
38
+ greater[stack.pop()] = value
39
+ stack.append(value)
40
+ lst_rlt = [greater.get(value, -1) for value in nums1]
41
+
42
+ ##########end上面可以改动
43
+ return lst_rlt
44
+
45
+ if __name__ == "__main__":
46
+ ###########下面可以修改
47
+ print(TEST_DO_NOT_CHANGE([4,1,2],[1,3,4,2]))
48
+ # 题号:hwc311
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:给定一个包括n 个整数的数组nums和一个目标值target。找出nums中的三个整数,使得它们的和与target最接近。
15
+ 返回这三个数的和。假定每组输入只存在唯一答案。
16
+
17
+ 示例:
18
+
19
+ 输入:nums = [-1,2,1,-4], target = 1
20
+ 输出:2
21
+ 解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。
22
+ '''
23
+
24
+ # 参考答案
25
+ def TEST_DO_NOT_CHANGE(nums,target):
26
+ result = None
27
+ ##########start下面可以改动
28
+
29
+ values = sorted(nums)
30
+ result = sum(values[:3])
31
+ for i in range(len(values) - 2):
32
+ left, right = i + 1, len(values) - 1
33
+ while left < right:
34
+ total = values[i] + values[left] + values[right]
35
+ if abs(total - target) < abs(result - target):
36
+ result = total
37
+ if total == target:
38
+ return total
39
+ if total < target:
40
+ left += 1
41
+ else:
42
+ right -= 1
43
+
44
+ ##########end上面可以改动
45
+ return result
46
+
47
+ if __name__ == "__main__":
48
+ ###########下面可以修改
49
+ print(TEST_DO_NOT_CHANGE([-1,2,1,-4],1))
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ 请只在 "
4
+ ##########start下面可以改动
5
+
6
+ ##########end上面可以改动 "
7
+
8
+ 中间部分作答,作答行数自由调整
9
+
10
+ 请不要使用 input() 函数
11
+
12
+ 此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
13
+
14
+ 题目:Z字形扫描
15
+ 在图像编码的算法中,需要将一个给定的方形矩阵进行Z字形扫描(Zigzag Scan)。
16
+
17
+ 例如,给定一个 n×n 的矩阵,沿 row+column 相等的对角线依次扫描;
18
+ 对角线编号为偶数时从右上向左下输出,编号为奇数时从左下向右上输出。
19
+ 输出列表包含 n×n 个整数,表示输入矩阵经过 Z 字形扫描后的结果。
20
+
21
+ 示例:
22
+ 输入:[[1,5,3,9],[3,7,5,6],[9,4,6,4],[7,3,1,3]]
23
+
24
+ 1 5 3 9
25
+ 3 7 5 6
26
+ 9 4 6 4
27
+ 7 3 1 3
28
+ 输出:[1,5,3,9,7,3,9,5,4,7,3,6,6,4,1,3]
29
+ '''
30
+
31
+ # 参考答案
32
+ def TEST_DO_NOT_CHANGE(lst_in):
33
+ lst_out = []
34
+ ##########start下面可以改动
35
+
36
+ # 采用原题示例的 JPEG Z 字形顺序(奇数对角线从右上到左下)。
37
+ n = len(lst_in)
38
+ for diagonal in range(2 * n - 1):
39
+ first = max(0, diagonal - n + 1)
40
+ last = min(n - 1, diagonal)
41
+ rows = range(first, last + 1) if diagonal % 2 else range(last, first - 1, -1)
42
+ lst_out.extend(lst_in[row][diagonal - row] for row in rows)
43
+
44
+ ##########end上面可以改动
45
+ return lst_out
46
+
47
+ if __name__ == "__main__":
48
+ ###########下面可以修改
49
+ lst_in = [[1, 5, 3, 9], [3, 7, 5, 6], [9, 4, 6, 4], [7, 3, 1, 3]]
50
+ print(TEST_DO_NOT_CHANGE(lst_in))
51
+
52
+
53
+
54
+ # 题号:hwc313