Cycle-07. Crawling worms

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.