当前位置:网站首页>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).
边栏推荐
- MicTR01 Tester 振弦采集模塊開發套件使用說明
- 一个程序员的水平能差到什么程度?尼玛,都是人才呀...
- Wechat applet - Advanced chapter component packaging - Implementation of icon component (I)
- 比尔·盖茨晒48年前简历:“没你们的好看”
- 全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
- 防火墙基础之服务器区的防护策略
- buffer overflow protection
- MicTR01 Tester 振弦采集模块开发套件使用说明
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- Internal sort - insert sort
猜你喜欢
How to enable radius two factor / two factor (2fa) identity authentication for Anheng fortress machine
数据湖(九):Iceberg特点详述和数据类型
Protection strategy of server area based on Firewall
在软件工程领域,搞科研的这十年!
15、文本编辑工具VIM使用
Substance painter notes: settings for multi display and multi-resolution displays
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
Base64 encoding
随机推荐
什么是云原生?这回终于能搞明白了!
JSON parsing instance (QT including source code)
⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
大厂做开源的五大痛点
Leetcode one question per day (636. exclusive time of functions)
安恒堡垒机如何启用Radius双因素/双因子(2FA)身份认证
Summary on adding content of background dynamic template builder usage
解析PHP跳出循环的方法以及continue、break、exit的区别介绍
电脑Win7系统桌面图标太大怎么调小
防火墙基础之服务器区的防护策略
Attribute keywords serveronly, sqlcolumnnumber, sqlcomputecode, sqlcomputed
#yyds干货盘点# 解决名企真题:交叉线
Démontage de la fonction du système multi - Merchant Mall 01 - architecture du produit
2022云顾问技术系列之高可用专场分享会
属性关键字OnDelete,Private,ReadOnly,Required
广州开发区让地理标志产品助力乡村振兴
Several ways of JS jump link
激光雷达lidar知识点滴
Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network