Cycle-07. Crawling worm (15) time limit MS Memory limit 65536 KB code length limit 8000 B procedure Standard
A worm is 1 inches long, at the bottom of a well with a deep n-inch. The worm is known to climb up to U-inch every 1 minutes, but must rest for 1 minutes to go up. In the course of the rest, the worm slipped down the D-inch. In this way, the climb and slide are repeated. Excuse me, how long does it take for the worm to crawl out of the well?
This requires less than 1 minutes of 1 minutes, and it is assumed that the worm will complete its task as long as the worm's head reaches the top of the well during a crawl. Initially, the worm is lying at the bottom of the hole (i.e. height is 0).
Input format:
The input gives 3 positive integers n, U, D in the order of one row, where d<u,n does not exceed 100.
Output format:
The time, in minutes, to output the worm's crawl out of the well in a row.
Input Sample:
12 3 1
Sample output:
11
1#include <stdio.h>2#include <stdlib.h>3#include <math.h>4 intMain ()5 {6 intN, u, D;7scanf"%d%d%d", &n, &u, &d);8 intt =0, L =0, i =0;9 while(L <N)Ten { One ifI2==0) AL + =u; - Else -L-=D; thei++; -t++; - } -printf"%d\n", T); + return 0; -}
Cycle-07. Crawling worms