当前位置:网站首页>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).
边栏推荐
- Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
- Es log error appreciation -- allow delete
- leetcode:648. Word replacement [dictionary tree board + find the shortest matching prefix among several prefixes]
- AWS learning notes (III)
- Yyds dry goods inventory # solve the real problem of famous enterprises: cross line
- Electronic remote error
- 半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
- Nllb-200: meta open source new model, which can translate 200 languages
- Simple use of websocket
- Simple steps for modifying IP of sigang electronic scale
猜你喜欢
Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
MicTR01 Tester 振弦采集模塊開發套件使用說明
JSON解析实例(Qt含源码)
Cocoscreator operates spine for animation fusion
[Yugong series] go teaching course 005 variables in July 2022
Deformable convolutional dense network for enhancing compressed video quality
今日睡眠质量记录78分
Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit
全球首款 RISC-V 笔记本电脑开启预售,专为元宇宙而生!
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
随机推荐
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
解析PHP跳出循环的方法以及continue、break、exit的区别介绍
Introduction and use of Kitti dataset
大厂做开源的五大痛点
[Yugong series] go teaching course 005 variables in July 2022
leetcode:648. 单词替换【字典树板子 + 寻找若干前缀中的最短符合前缀】
一文读懂数仓中的pg_stat
Substance Painter筆記:多顯示器且多分辨率顯示器時的設置
Read PG in data warehouse in one article_ stat
Démontage de la fonction du système multi - Merchant Mall 01 - architecture du produit
Read PG in data warehouse in one article_ stat
WebRTC 音频抗弱网技术(上)
半小时『直播连麦搭建』动手实战,大学生技术岗位简历加分项get!
Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
ES日志报错赏析-- allow delete
6、Electron无边框窗口和透明窗口 锁定模式 设置窗口图标
数据库如何进行动态自定义排序?
MicTR01 Tester 振弦采集模塊開發套件使用說明
Emqx 5.0 release: open source Internet of things message server with single cluster supporting 100million mqtt connections
【愚公系列】2022年7月 Go教学课程 005-变量