CF#421 A. Mister B and Book Reading(模拟)
2017-09-06 10:22
369 查看
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: 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.
Output
Print one integer — the number of days Mister B needed to finish the book.
Examples
input
output
input
output
input
output
Note
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.
模拟一下就出来了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
#include <stdlib.h>
#define lowbit(x) (x&-x)
#define e exp(1.0)
#define eps 1e-8
//ios::sync_with_stdio(false);
// auto start = clock();
// cout << (clock() - start) / (double)CLOCKS_PER_SEC<<endl;
typedef long long ll;
typedef long long LL;
using namespace std;
typedef unsigned long long ull;
int main()
{
ios::sync_with_stdio(false);
int c,v0,v1,a,l,ans;
while(cin>>c>>v0>>v1>>a>>l)
{
ans=0;
int n=c;
int v;
while(n>0)
{
if(ans!=0) n=n+l;
v=min(v0+a*ans,v1);
n=n-v;
ans++;
}
cout<<ans<<endl;
}
return 0;
}
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: 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.
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
Note
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.
模拟一下就出来了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <stack>
#include <stdlib.h>
#define lowbit(x) (x&-x)
#define e exp(1.0)
#define eps 1e-8
//ios::sync_with_stdio(false);
// auto start = clock();
// cout << (clock() - start) / (double)CLOCKS_PER_SEC<<endl;
typedef long long ll;
typedef long long LL;
using namespace std;
typedef unsigned long long ull;
int main()
{
ios::sync_with_stdio(false);
int c,v0,v1,a,l,ans;
while(cin>>c>>v0>>v1>>a>>l)
{
ans=0;
int n=c;
int v;
while(n>0)
{
if(ans!=0) n=n+l;
v=min(v0+a*ans,v1);
n=n-v;
ans++;
}
cout<<ans<<endl;
}
return 0;
}
相关文章推荐
- CF820A-Mister B and Book Reading
- Mister B and Book Reading
- 【Codeforces Round #421 (Div. 2) A】Mister B and Book Reading
- Codeforces Round #421 (Div. 2) | A. Mister B and Book Reading
- Mister B and Book Reading
- Codeforces Round #421 A. Mister B and Book Reading
- Codeforces Round #421 (Div. 2) A. Mister B and Book Reading
- 【CF819D】Mister B and Astronomers EXGCD
- Codeforces Round #421 (Div. 2) C. Mister B and Boring Game
- Codeforces 819 B. Mister B and PR Shifts - 模拟
- B. Mister B and Angle in Polygon 421.div2
- CF #421 B. Mister B and Angle in Polygon
- PAT - 甲级 - 1065. A+B and C (64bit) (20)(模拟)
- Codeforces 819 A. Mister B and Boring Game
- [数论] Codeforces819D. Mister B and Astronomers
- #421 Div.2 B. Mister B and Angle in Polygon——几何数学
- Codeforces 819 C. Mister B and Beacons on Field 容斥 数学
- A. Mister B and Book Reading
- 【CF819C】Mister B and Beacons on Field 数学
- [数论] Codeforces 819D R #421 D.Mister B and Astronomers & 516E R #292 E. Drazil and His Happy Friends