当前位置:网站首页>Lesson 1: hardness of eggs
Lesson 1: hardness of eggs
2022-07-07 09:32:00 【Fight! Sao Nian!】
subject :AcWing 1048. The hardness of the egg
lately XX The company held a strange competition : The king of egg hardness competition .
The contestants are hens from all over the world , The content of the competition is to see who lays the hardest egg , What's more strange is that XX The company does not use any precision instruments to measure the hardness of eggs , They adopted the most old-fashioned method – Throw eggs from height – To test the hardness of eggs , If a hen lays an egg from the top of a tall building a The layer fell without breaking , But from a+1 The floor broke when it fell , Then say that the hardness of this hen's egg is a.
Of course, you can find various reasons to explain that this method is unscientific , For example, the hardness of the eggs laid by the same hen may be different, and so on , But it doesn't affect XX The competition of the company , Because they just want to attract everyone's attention , Eggs come from 100 When falling from a high building on the first floor , This scene can still attract many people to stop and watch , Of course ,XX The company will never forget to hang a banner on the tall building , write “XX company ” The words... – This game is just XX An alternative advertisement of the company .
Diligent little A You can always find a mathematical problem in one thing , This is no exception .
“ If there are many eggs with the same hardness , Then I can use the method of two points to measure the hardness of the egg with the least number of times ”, Small A I am very satisfied with my conclusion , But soon trouble came ,“ however , What if I don't have enough eggs , For example, I only have 1 An egg , Then I have to start from 1 Throw it from floor to floor , At worst, I will throw 100 Time . If there is 2 An egg , Then from 2 Throw it at the beginning of the first floor …… wait , incorrect , It seems that we should start from 1/3 It's the right place to start throwing , Um. , I don't think so ……3 What about an egg ,4 individual ,5 individual , More ……”, As usual , Small A Another thinking impasse , He is not so much diligent in thinking , Rather, he likes to ask for trouble .
ok , Now that the trouble has come , Someone has to solve it , Small A It's up to you to solve the problem .
Input format
Input includes multiple sets of data , One line for each group of data , Contains two positive integers n and m, among n Indicates the height of the building ,m It means the number of eggs you have now , These eggs have the same hardness ( That is, when they fall from the same height, they either break or don't break ), And less than or equal to n.
You can assume that the hardness is x The height of eggs is less than or equal to x The place where you fall will not break anyway ( Unbroken eggs can be used ), As long as we compare x If you throw it high, it will break .
Enter data for each group , You can assume that the hardness of the egg is 0 to n Between , That is to say n+1 Throwing eggs in layers will surely break .
Output format
For each set of inputs , Output an integer , Indicates the number of egg throwing times required in the worst case using the optimal strategy .
Data range
1≤n≤100,
1≤m≤10
sample input :
100 1
100 2
sample output :
100
14
Sample explanation
The optimal strategy refers to the strategy that needs the least egg throwing times in the worst case .
If there is only one egg , You can only throw it from the first floor , In the worst case , The hardness of an egg is 100, So you need to throw 100 Time . If other strategies are adopted , You may not be able to measure the hardness of an egg ( For example, you throw it on the second floor for the first time , It broke , At this time, you cannot be sure that the hardness is 0 still 1), That is, in the worst case, you need to throw unlimited times , So the answer to the first set of data is 100.
Topic analysis :
Because this problem is more complex, it will be continued ...
Here's an explanation 100 floor ,2 An egg only needs 14 How did the second come
We can use the answer 14 infer
If we stand for the first time 14 floor , If it is broken, we still need to judge 1~13 Lou Gong 13 Time , So add the first egg altogether 1+13=14 Time ;
If we stand here for the second time 14+13 floor , If it is broken, we still need to judge 15~26 common 12 Time , So add the first time and the second time 1+1+12=14 Time .
By analogy, we can know that we can definitely reach 100 layer .
边栏推荐
- Leetcode daily questions (2316. count unreachable pairs of nodes in an undirected graph)
- The configuration and options of save actions are explained in detail, and you won't be confused after reading it
- Loxodonframework quick start
- How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
- Redis common commands
- 数据建模中利用3σ剔除异常值进行数据清洗
- Colorbar of using vertexehelper to customize controls (II)
- flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
- stm32和电机开发(从单机版到网络化)
- Record of structured interview
猜你喜欢
Locust performance test 3 (high concurrency, parameter correlation, assembly point)
Pytest+request+allure+excel interface automatic construction from 0 to 1 [familiar with framework structure]
【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
Cesium load vector data
Binary tree high frequency question type
沙龙预告|GameFi 领域的瓶颈和解决方案
How to speed up video playback in browser
四、机器学习基础
Jenkins task grouping
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
随机推荐
CMD startup software passes in parameters with spaces
Self awakening from a 30-year-old female programmer
When inputting an expression in the input box, an error is reported: incorrect string value:'\xf0\x9f... ' for column 'XXX' at row 1
Huawei hcip datacom core_ 03day
战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
Oracle安装增强功能出错
Skill review of test engineer before interview
Information Security Experiment 4: implementation of IP packet monitoring program
Confitest of fixture py
信息安全实验三 :PGP邮件加密软件的使用
Zen - batch import test cases
Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
面试被问到了解哪些开发模型?看这一篇就够了
软件建模与分析
[SVN] what is SVN? How do you use it?
Sublime Text4 download the view in bower and set the shortcut key
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
【云原生】DevOps(一):DevOps介绍及Code工具使用
Unity shader (to achieve a simple material effect with adjustable color attributes only)
MySQL common statements