当前位置:网站首页>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;
}
边栏推荐
- [on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
- Explanation of closures in golang
- 智能网关助力提高工业数据采集和利用
- Report on the development trend and prospect trend of high purity zinc antimonide market in the world and China Ⓕ 2022 ~ 2027
- How web pages interact with applets
- Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share
- Qtreeview+ custom model implementation example
- At the age of 30, I changed to Hongmeng with a high salary because I did these three things
- 百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
- How does idea withdraw code from remote push
猜你喜欢
2022-2028 global edible probiotic raw material industry research and trend analysis report
How web pages interact with applets
Hands on deep learning (39) -- gating cycle unit Gru
You can see the employment prospects of PMP project management
165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
Four common methods of copying object attributes (summarize the highest efficiency)
2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
SQL replying to comments
At the age of 30, I changed to Hongmeng with a high salary because I did these three things
随机推荐
Explanation of for loop in golang
Golang type comparison
浅谈Multus CNI
Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
The child container margin top acts on the parent container
How to batch change file extensions in win10
PMP registration process and precautions
Fabric of kubernetes CNI plug-in
品牌连锁店5G/4G无线组网方案
Lauchpad X | 模式
C语言指针面试题——第二弹
Implementing expired localstorage cache with lazy deletion and scheduled deletion
Four common methods of copying object attributes (summarize the highest efficiency)
Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
【leetcode】29. Divide two numbers
SQL replying to comments
法向量点云旋转
Hands on deep learning (32) -- fully connected convolutional neural network FCN
How to display √ 2 on the command line terminal ̅? This is actually a blog's Unicode test article
DR6018-CP01-wifi6-Qualcomm-IPQ6010-IPQ6018-FAMILY-2T2R-2.5G-ETH-port-CP01-802-11AX-MU-MIMO-OFDMA