当前位置:网站首页>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;
}
边栏推荐
- Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
- PMP registration process and precautions
- System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
- Tkinter Huarong Road 4x4 tutorial II
- MySQL transaction mvcc principle
- Multilingual Wikipedia website source code development part II
- IIS configure FTP website
- Latex download installation record
- el-table单选并隐藏全选框
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
猜你喜欢
2022-2028 global elastic strain sensor industry research and trend analysis report
Summary of small program performance optimization practice
Mmclassification annotation file generation
el-table单选并隐藏全选框
How web pages interact with applets
品牌连锁店5G/4G无线组网方案
What are the advantages of automation?
C language pointer interview question - the second bullet
The child container margin top acts on the parent container
Summary of reasons for web side automation test failure
随机推荐
You can see the employment prospects of PMP project management
智能网关助力提高工业数据采集和利用
回复评论的sql
Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
mmclassification 标注文件生成
Daughter love: frequency spectrum analysis of a piece of music
【leetcode】540. A single element in an ordered array
Tkinter Huarong Road 4x4 tutorial II
技术管理进阶——如何设计并跟进不同层级同学的绩效
Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
Implementing expired localstorage cache with lazy deletion and scheduled deletion
2022-2028 global edible probiotic raw material industry research and trend analysis report
Latex download installation record
Hands on deep learning (34) -- sequence model
Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share
Write a jison parser from scratch (1/10):jison, not JSON
Golang Modules
Kotlin:集合使用
Go context basic introduction
Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027