当前位置:网站首页>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 :

边栏推荐
- Differences between cookies and sessions
- Summary on adding content of background dynamic template builder usage
- MicTR01 Tester 振弦采集模塊開發套件使用說明
- PG基础篇--逻辑结构管理(锁机制--表锁)
- [server data recovery] a case of RAID data recovery of a brand StorageWorks server
- 昇腾体验官第五期随手记I
- 属性关键字OnDelete,Private,ReadOnly,Required
- Data Lake (IX): Iceberg features and data types
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- Andriod --- JetPack :LiveData setValue 和 postValue 的区别
猜你喜欢

Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)

【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例

Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)

Substance Painter笔记:多显示器且多分辨率显示器时的设置

15、文本编辑工具VIM使用

Yyds dry goods inventory # solve the real problem of famous enterprises: cross line

"July 2022" Wukong editor update record

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

JSON解析实例(Qt含源码)

CPU与chiplet技术杂谈
随机推荐
Demis hassabis talks about alphafold's future goals
PyTorch模型训练实战技巧,突破速度瓶颈
Applet directory structure
【历史上的今天】7 月 7 日:C# 发布;Chrome OS 问世;《仙剑奇侠传》发行
Instructions d'utilisation de la trousse de développement du module d'acquisition d'accord du testeur mictr01
Reading and understanding of eventbus source code
"July 2022" Wukong editor update record
PD virtual machine tutorial: how to set the available shortcut keys in the parallelsdesktop virtual machine?
「2022年7月」WuKong编辑器更版记录
Attribute keywords serveronly, sqlcolumnnumber, sqlcomputecode, sqlcomputed
CPU与chiplet技术杂谈
因员工将密码设为“123456”,AMD 被盗 450Gb 数据?
Substance painter notes: settings for multi display and multi-resolution displays
拜拜了,大厂!今天我就要去厂里
2022 cloud consulting technology series high availability special sharing meeting
Simple steps for modifying IP of sigang electronic scale
Small game design framework
华为云数据库DDS产品深度赋能
Andriod --- JetPack :LiveData setValue 和 postValue 的区别
leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】