杭电ACM1049题

这里写图片描述

这就是小学的一道奥数题:小爬虫,总距离是n,每次能爬u,休息时会下滑d。问需要多久才能爬上来。

#include<stdio.h>
int main()
{
    int n,u,d;
    while(scanf("%d %d %d",&n,&u,&d)!=EOF)
    {
        int height=0,time=0;
        if(n==0&&u==0&&d==0)
        {
            break;
        }
        while(height+u<n)
        {
            height+=u-d;
            time+=2;
        }
        if(height+u>=n)
        {
            time++;
        }
        printf("%d\n",time);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43104182/article/details/82629380