当前位置:网站首页>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 :
边栏推荐
- Mmkv use and principle
- 广州开发区让地理标志产品助力乡村振兴
- Several ways of JS jump link
- Discussion on CPU and chiplet Technology
- Instructions for mictr01 tester vibrating string acquisition module development kit
- Protection strategy of server area based on Firewall
- 一个程序员的水平能差到什么程度?尼玛,都是人才呀...
- Computer win7 system desktop icon is too large, how to turn it down
- 时空可变形卷积用于压缩视频质量增强(STDF)
- WebRTC 音频抗弱网技术(上)
猜你喜欢
Beginner JSP
[Yugong series] go teaching course 005 variables in July 2022
13 ux/ui/ue best creative inspiration websites in 2022
⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
Webrtc audio anti weak network technology (Part 1)
WebRTC 音频抗弱网技术(上)
The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】
随机推荐
13 ux/ui/ue best creative inspiration websites in 2022
数据湖(九):Iceberg特点详述和数据类型
Half an hour of hands-on practice of "live broadcast Lianmai construction", college students' resume of technical posts plus points get!
潘多拉 IOT 开发板学习(HAL 库)—— 实验12 RTC实时时钟实验(学习笔记)
时空可变形卷积用于压缩视频质量增强(STDF)
2022年13个UX/UI/UE最佳创意灵感网站
Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network
电脑Win7系统桌面图标太大怎么调小
缓冲区溢出保护
What is cloud primordial? This time, I can finally understand!
一款你不容错过的Laravel后台管理扩展包 —— Voyager
Read PG in data warehouse in one article_ stat
寺岗电子称修改IP简易步骤
广州开发区让地理标志产品助力乡村振兴
安恒堡垒机如何启用Radius双因素/双因子(2FA)身份认证
Jetson AGX Orin CANFD 使用
华为云数据库DDS产品深度赋能
防火墙基础之服务器区的防护策略
In the field of software engineering, we have been doing scientific research for ten years!
Cocoscreator operates spine for animation fusion