题目链接:Death Note
题意
有一本死亡笔记,这本死亡笔记有无穷多页,每一页能够写下 行名字,死亡笔记要求从第 天到第 天,每天都要在笔记本上写下 行名字,死亡笔记只有在写到最后一行的时候才会翻页,问第 天会翻多少页。
输入
第一行包含两个整数 ,第二行为 个整数 。
输出
输出 个整数 , 表示第 天翻页的次数。
样例
输入 |
---|
3 5 3 7 9 |
输出 |
0 2 1 |
提示 |
死亡笔记上每一页的名字为: ,每一个中括号的内容是每一页的名字,其中的数字 表示第 天需要写下的名字。 |
输入 |
---|
4 20 10 9 19 2 |
输出 |
0 0 1 1 |
输入 |
---|
1 100 99 |
输出 |
0 |
题解
记录写的行数,按照题意模拟。
过题代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;
#define LL long long
LL n, m, now, cnt, page;
int main() {
#ifdef Dmaxiya
freopen("test.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif // Dmaxiya
ios::sync_with_stdio(false);
while(scanf("%I64d%I64d", &n, &m) != EOF) {
now = 0;
for(int i = 1; i <= n; ++i) {
if(i != 1) {
printf(" ");
}
scanf("%I64d", &page);
if(page >= m - now) {
page -= m - now;
printf("%I64d", page / m + 1);
now = page % m;
} else {
now += page;
printf("0");
}
}
printf("\n");
}
return 0;
}