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.
First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ 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.
Print one integer — the number of days Mister B needed to finish the book.
5 5 10 5 4
1
12 4 12 4 1
3
15 1 100 0 0
15
In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
题意:读一本书,书共有c页,第一天读v0,第二天读v0+a,第三天比前天多a页,但是最快一天不能超过v1,而且要回读 l 页,
逆向思维
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 int c,v0,v1,a,l,t,k,ans=0; 5 int main(){ 6 scanf("%d %d %d %d %d",&c, &v0, &v1, &a, &l); 7 k=v0; 8 t=0; 9 while(c){ 10 ans++; 11 c-=v0; 12 v0=min(v0+a, v1); 13 if (c<=0) {cout<<ans<<endl; break;} 14 c+=l; 15 } 16 17 return 0; 18 }