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

边栏推荐
- C 6.0 language specification approved
- Decrypt the three dimensional design of the game
- A laravel background management expansion package you can't miss - Voyager
- Huawei cloud database DDS products are deeply enabled
- 广州开发区让地理标志产品助力乡村振兴
- 今日睡眠质量记录78分
- Data Lake (IX): Iceberg features and data types
- Ian Goodfellow, the inventor of Gan, officially joined deepmind as research scientist
- 大厂做开源的五大痛点
- Differences between cookies and sessions
猜你喜欢

KITTI数据集简介与使用

Notes de l'imprimante substance: paramètres pour les affichages Multi - écrans et multi - Résolutions

Because the employee set the password to "123456", amd stolen 450gb data?

MicTR01 Tester 振弦采集模块开发套件使用说明

Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an

Introduction and use of Kitti dataset

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

Xiaomi's path of chip self-development

Discussion on CPU and chiplet Technology

The world's first risc-v notebook computer is on pre-sale, which is designed for the meta universe!
随机推荐
昇腾体验官第五期随手记I
防火墙基础之服务器区的防护策略
buffer overflow protection
[Yugong series] go teaching course 005 variables in July 2022
电脑Win7系统桌面图标太大怎么调小
数据湖(九):Iceberg特点详述和数据类型
IDA pro逆向工具寻找socket server的IP和port
MicTR01 Tester 振弦采集模块开发套件使用说明
PyTorch模型训练实战技巧,突破速度瓶颈
一文读懂数仓中的pg_stat
一文读懂数仓中的pg_stat
Shengteng experience officer Episode 5 notes I
Jetson AGX Orin CANFD 使用
Base64 encoding
JS in the browser Base64, URL, blob mutual conversion
拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条...
Differences between cookies and sessions
Attribute keywords serveronly, sqlcolumnnumber, sqlcomputecode, sqlcomputed
6、Electron无边框窗口和透明窗口 锁定模式 设置窗口图标
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight