当前位置:网站首页>7-17 crawling worms (15 points)
7-17 crawling worms (15 points)
2022-07-04 09:42:00 【skeet follower】
A worm is long 1 " , In a deep for N The bottom of the well . Known worms every 1 Minutes to climb up U " , But must rest 1 Minutes to climb up . In the process of rest , The worm has slipped again D " . That's it , Go up and down again . Excuse me, , How long does it take for the worm to climb out of the well ?
There is not enough demand here 1 Minutes press 1 Minute meter , And assume that as long as the head of the worm reaches the top of the well during a climb , So the worm is done . At the beginning , Worms lie at the bottom of the well ( That is, the height is 0).
Input format :
The input is given in order on one line 3 A positive integer N、U、D, among D<U,N No more than 100.
Output format :
Output the time when the worm climbed out of the well in one line , In minutes .
sample input :
12 3 1
sample output :
11
Their thinking : I think the difficulty of the problem is when to climb up and fall down , In fact, you will find that climbing up is time t All are 1,3,5 Odd number , And the number falling down is even , Then just judge t Whether it is a prime number or not , But we should also consider the situation that the initial upward climb is greater than or equal to the well depth , for example :2,3,1;
The code is as follows :
#include<stdio.h>
int main()
{
int N,U,D,h=0,t;
scanf("%d %d %d\n",&N,&U,&D);
for(t=1;h<N;t++){
if(t%2!=0){
h+=U;
if(h>=N){
break;
}
}
else{
h-=D;
}
}
printf("%d",t);
return 0;
}
边栏推荐
- How should PMP learning ideas be realized?
- Deadlock in channel
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
- HMS core helps baby bus show high-quality children's digital content to global developers
- 自动化的优点有哪些?
- 2022-2028 global probiotics industry research and trend analysis report
- Daughter love: frequency spectrum analysis of a piece of music
- At the age of 30, I changed to Hongmeng with a high salary because I did these three things
- C语言指针经典面试题——第一弹
- Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
猜你喜欢
el-table单选并隐藏全选框
2022-2028 global edible probiotic raw material industry research and trend analysis report
Fabric of kubernetes CNI plug-in
Hands on deep learning (33) -- style transfer
If you can quickly generate a dictionary from two lists
PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
After unplugging the network cable, does the original TCP connection still exist?
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
华为联机对战如何提升玩家匹配成功几率
PHP book borrowing management system, with complete functions, supports user foreground management and background management, and supports the latest version of PHP 7 x. Database mysql
随机推荐
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
el-table单选并隐藏全选框
Hands on deep learning (33) -- style transfer
2022-2028 global probiotics industry research and trend analysis report
Daughter love: frequency spectrum analysis of a piece of music
Hands on deep learning (35) -- text preprocessing (NLP)
pcl::fromROSMsg报警告Failed to find match for field ‘intensity‘.
Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
H5 audio tag custom style modification and adding playback control events
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
Some points needing attention in PMP learning
Qtreeview+ custom model implementation example
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
Multilingual Wikipedia website source code development part II
Rules for using init in golang
How can people not love the amazing design of XXL job