Codeforces 1016A Death Note(模拟)

题目链接:Death Note

题意

有一本死亡笔记,这本死亡笔记有无穷多页,每一页能够写下 m 行名字,死亡笔记要求从第 1 天到第 n 天,每天都要在笔记本上写下 a i 行名字,死亡笔记只有在写到最后一行的时候才会翻页,问第 i 天会翻多少页。

输入

第一行包含两个整数 n , m   ( 1 n 2 × 10 5 , 1 m 10 9 ) ,第二行为 n 个整数 a 1 , a 2 , , a n   ( 1 a i 10 9 )

输出

输出 n 个整数 t 1 , t 2 , , t n t i 表示第 i 天翻页的次数。

样例

输入
3 5
3 7 9
输出
0 2 1
提示
死亡笔记上每一页的名字为: [ 1 , 1 , 1 , 2 , 2 ] , [ 2 , 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 , 3 ] , [ 3 , 3 , 3 , 3 ] ,每一个中括号的内容是每一页的名字,其中的数字 i 表示第 i 天需要写下的名字。
输入
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;
}

猜你喜欢

转载自blog.csdn.net/CSDNjiangshan/article/details/81408335