Zoj 1494 climbing Worm

Source: Internet
Author: User

Zoj 1494 climbing worm {4491}

A snail can climb from the bottom of a well every minute, and then fall down a certain distance in one minute. If the whole minute is not over, it will arrive at the wellhead. It will take one minute, if the minute of the climb arrives at the wellhead, it will not fall down. For the depth of the well, the distance between the climbing per minute is used to find the time to climb out of the wellhead.

Idea: This was a long time ago when I had the same question on hangdian in Activity Room. If the previous minute's climb does not reach the wellhead, there will be a certain distance and time to fall down, and the two distances and time cycles will be accumulated, until the distance from the next minute is greater than or equal to the distance from the wellhead, this minute is accumulated.

The code can be slightly improved. For more information, see comments.

# Include <stdio. h> int main () {int N, U, D, I, T; while (scanf ("% d", & N, & U, & D )! = EOF) {If (0 = N & 0 = u & 0 = d) break; If (n <= u) {T = 1 ;} else {for (I = 1; I ++) // here I starts from 0, so you do not need to list the first minute separately, every minute is the same, and so on. If (n <= (u-d) * I + u) break; t = 2 * I + 1;} printf ("% d \ n", T );} return 0 ;}

 

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.