当前位置:网站首页>Niuke real problem programming - day13
Niuke real problem programming - day13
2022-07-07 14:53:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Programming environment :c++
1、 Building blocks
describe
Xiao Ming has a bag of rectangular building blocks , If a building block A The length and width of is no larger than another building block B The length and width of , Then the building blocks A It can be built on building blocks B On top of . Curious Xiao Ming especially wants to know how many layers this bag of building blocks can be built at most , Can you help him find a way ?
Define the length of each rectangle L And width W , The number of rectangles in the bag is n .
If there are 5 The building blocks are (2, 2), (2, 4), (3, 3), (2, 5), (4, 5), It is not difficult to judge that these building blocks can be built at most 4 layer , because (2, 2) < (2, 4) < (2, 5) < (4, 5).
Algorithmic thought :
The title requires that the length and width of the upper layer of building blocks should be smaller than that of the lower layer , Find the longest number of layers . First, we will arrange all rectangular building blocks in ascending order according to the length first , Then traverse to get all the widths after sorting , Get a new array . Because the time required by the topic is relatively limited , So here we choose the dichotomy with the best time complexity to sort , Get a wide ascending priority subsequence , The size of the printout subsequence is the longest number of layers .
The code part implements :
Two points ,len Is the length of the subsequence
2、 Odd number
describe :
Small M Suddenly interested in odd numbers . Suppose a number n, If [n/1]+[n/2]+...+[n/k](k Is a positive integer approaching positive infinity ) It's an even number , Then this number is an odd number , Now let's give an interval [a,b], seek [a,b] How many strange numbers are there between .
[x] No greater than x Maximum integer for .
Algorithmic thought :
Solve problems with mathematical ideas : according to 100 It is not difficult to find the odd number data within the enumeration ,, In each line i For even when , In the interval [i2,(i+1)2)] The inner numbers are all odd numbers that meet the requirements . So according to the scope given by the title ab, First, traverse to the smallest i Satisfy i^2>=a, Yes ab Judge the middle number , When i-1 For even when , Add the odd number in the range ; otherwise ,i++ Extend back , until i^2 beyond b Range . After the last judgment , Print out the final result .

The code part implements :

3、 The largest sum of successive subarrays
describe
Enter an array of integers ( There could be positive and negative numbers ), Find a continuous subarray in an array ( At least one element ) The largest sum of . The required time complexity is O(n).
Algorithmic thought : Abandon the past and <0 Part of and , Get the sum of the largest subarray after traversal .
Part of the code implementation :

边栏推荐
- 缓冲区溢出保护
- Stm32cubemx, 68 sets of components, following 10 open source protocols
- ES日志报错赏析-trying to create too many buckets
- Multi merchant mall system function disassembly lecture 01 - Product Architecture
- 智汀不用Home Assistant让小米智能家居接入HomeKit
- Analysis of arouter
- 6. Electron borderless window and transparent window lock mode setting window icon
- Reading and understanding of eventbus source code
- 电脑Win7系统桌面图标太大怎么调小
- Data connection mode in low code platform (Part 2)
猜你喜欢

What is the process of ⼀ objects from loading into JVM to being cleared by GC?

全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!

智汀不用Home Assistant让小米智能家居接入HomeKit

What is cloud primordial? This time, I can finally understand!

拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...
![[today in history] July 7: release of C; Chrome OS came out;](/img/a6/3170080268a836f2e0973916d737dc.png)
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued

Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit

云上“视界” 创新无限 | 2022阿里云直播峰会正式上线

用于增强压缩视频质量的可变形卷积密集网络

Stm32cubemx, 68 sets of components, following 10 open source protocols
随机推荐
Full details of efficientnet model
Webrtc audio anti weak network technology (Part 1)
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
比尔·盖茨晒48年前简历:“没你们的好看”
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
Cocoscreator resource encryption and decryption
Simple steps for modifying IP of sigang electronic scale
Data connection mode in low code platform (Part 2)
PD虚拟机教程:如何在ParallelsDesktop虚拟机中设置可使用的快捷键?
Reading and understanding of eventbus source code
Delete a whole page in word
MicTR01 Tester 振弦采集模块开发套件使用说明
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
C 6.0 language specification approved
CPU与chiplet技术杂谈
PAG体验:十分钟完成AE动效部署上线各平台!
缓冲区溢出保护
大厂做开源的五大痛点
How to enable radius two factor / two factor (2fa) identity authentication for Anheng fortress machine
What is cloud primordial? This time, I can finally understand!