当前位置:网站首页>Niuke real problem programming - Day12
Niuke real problem programming - Day12
2022-07-07 14:53:00 【weixin_ forty-five million seven hundred and fifty thousand fou】
Compile environment :c++
1、 street lamp
describe :
One is long l There are n Street lights , If the starting point of this street is 0, The finish for l, The first i The coordinates of street lights are ai , The longest distance that each lamp can cover is d, For lighting needs , All lights must cover the whole street , But in order to save electricity , To make this d Minimum , Please find the smallest d.
Algorithmic thought :
The topic requires finding the smallest lighting range of street lamps , In fact, it is to sort the input disordered street lamp positions , Find the maximum distance between adjacent street lamps , Boundary also needs to be considered , Take the maximum value and output . Note that the title has multiple groups of inputs and the output retains two decimal places .
The code part implements :

2、 Xiaoyi's upgrade road
describe
Xiaoyi often indulges in online games . There is a , He's playing a strange upgrade game , His character's initial ability value is a. Over the next period of time , He will meet in turn n A monster , Each monster's defense is b1,b2,b3...bn. If you encounter a monster defense bi Less than or equal to Xiaoyi's current ability value c, Then he can easily defeat the monster , and And increase your ability value bi; If bi Greater than c, Then he can also defeat monsters , But his ability value can only increase bi And c Maximum common divisor of . So here comes the question , After a series of exercises , What is the final ability value of Xiaoyi ?
Algorithmic thought :
The title description is very clear , Requirements bi and a Common divisor of ability value or directly defeat , Output the capability value after the final upgrade . The topic has multiple sets of use case input .
The code part implements :

3、 Pig in the tuyere - China's bull market
describe :
Under the wind , Pigs can fly . Today's Chinese stock market is a bull market , It can be said. “ Miss waiting seven years ”. Give you a chance to look back on history , A stock is known to be n The price trend of the day , In length n An array of integers representing , No i Elements (prices[i]) Represents the number i Day's share price . Suppose you didn't have stocks at first , But there are at most two purchases 1 Shares then sold 1 The opportunity of stock market , And before you buy, you must make sure that you don't have any stocks . If you give up both trading opportunities , Yield is 0. Design algorithm , Calculate the maximum benefit you can get . Input value range :2<=n<=100,0<=prices[i]<=100
Algorithmic thought :
Use the double pointer thought , Because you can't continue to buy when you have stocks , So we can distinguish the two stock transactions . Traversing from front to back , Go back and forth , Before calculating separately i The maximum return of the stock that can be obtained in days and after n-i Day's biggest gain , Stored in an array , Then there will be n-1 In this case : front 2 God , after n-2 God ; front 3 God , after n-3 God ... Finally, traverse the result array , Take the maximum value of the sum of the two and print it out . The time complexity of each traversal is n, So the total time complexity is O(n).

边栏推荐
- 云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
- 全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
- Mmkv use and principle
- 激光雷達lidar知識點滴
- 广州开发区让地理标志产品助力乡村振兴
- Substance Painter笔记:多显示器且多分辨率显示器时的设置
- Shengteng experience officer Episode 5 notes I
- PD virtual machine tutorial: how to set the available shortcut keys in the parallelsdesktop virtual machine?
- 什么是云原生?这回终于能搞明白了!
- asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
猜你喜欢

比尔·盖茨晒48年前简历:“没你们的好看”

MicTR01 Tester 振弦采集模塊開發套件使用說明

13 ux/ui/ue best creative inspiration websites in 2022

Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched

leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】

华为云数据库DDS产品深度赋能

Internal sort - insert sort

Multi merchant mall system function disassembly lecture 01 - Product Architecture

大厂做开源的五大痛点

JSON parsing instance (QT including source code)
随机推荐
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
[Yugong series] go teaching course 005 variables in July 2022
asp.netNBA信息管理系统VS开发sqlserver数据库web结构c#编程计算机网页源码项目详细设计
ES日志报错赏析-maximum shards open
【愚公系列】2022年7月 Go教学课程 005-变量
The method of parsing PHP to jump out of the loop and the difference between continue, break and exit
PG基础篇--逻辑结构管理(锁机制--表锁)
Introduction and use of Kitti dataset
How does the database perform dynamic custom sorting?
asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
PyTorch模型训练实战技巧,突破速度瓶颈
PG basics -- Logical Structure Management (locking mechanism -- table lock)
leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
In the field of software engineering, we have been doing scientific research for ten years!
8大模块、40个思维模型,打破思维桎梏,满足你工作不同阶段、场景的思维需求,赶紧收藏慢慢学
WebRTC 音频抗弱网技术(上)
#yyds干货盘点# 解决名企真题:交叉线
KITTI数据集简介与使用
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
2022 cloud consulting technology series high availability special sharing meeting