Mister B and Book Reading

题目链接http://codeforces.com/problemset/problem/820/A

A. Mister B and Book Reading
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.

At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.

Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.

Help Mister B to calculate how many days he needed to finish the book.

Input

First and only line contains five space-separated integers: cv0v1a and l (1 ≤ c ≤ 10000 ≤ l < v0 ≤ v1 ≤ 10000 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.

Output

Print one integer — the number of days Mister B needed to finish the book.

Examples
input
5 5 10 5 4
output
1
input
12 4 12 4 1
output
3
input
15 1 100 0 0
output
15
题目大意:

有一本书共c页,一个人他想要看这本书,他第一天看v0页,第二天看v0+a页(但是要先复习前一天看的L页,也就是第二天提前L页看),第三天看v0+2*a页(也要提前L页看)......但是他每天最多能够看书v1页。

解题思路:

这就是一个简单的数学问题,需要注意的是:第一天他不应复习着看;书一旦看完就是结束观看。

代码:

#include<iostream>
using namespace std;
int main()
{
    int c,v0,v1,v,a,l,page;
    while(cin>>c>>v0>>v1>>a>>l)
    {
        int i=0;
        for(;;i++)
        {
            if(i==0)         //第一天就是v0,不多看,也就是没有加速度
                v=v0;
            else
                v=v0+i*a;
            if(v>=v1)        //如果当天看书的页数超过最大看书页数,那么只能按照最大看书页数进行看书
                v=v1;
            if(i==0)         //i=0表示第一天,第一天不用复习着看,所以不用+L
                c=c-v;
            else
                c=c-v+l;     //不是第一天的话,需要复习着看,剩余的页数还需要+L
            if(c<=0)
                break;
        }
        cout<<i+1<<endl;     //i是从0开始的,所以天数应+1
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值