Codeforces 1016A Death Note 题解

题目:

点击链接即可:http://codeforces.com/problemset/problem/1016/A

背景:

You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: “You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly ai names.”. You got scared (of course you got scared, who wouldn’t get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn’t matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page. Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.

提示:

这道题是道模拟题,题目怎么说,你就怎么做就行了。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200001
using namespace std;
int n,m,a[N];
int main ( )
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int ls=m,ans;
    for(int i=1;i<=n;i++)
    {
        ans=0;
        if(a[i]<ls) ls-=a[i];
        else
        {
            a[i]-=ls;
            ls=m;
            ans++;
            ans+=a[i]/m;
            ls=m-(a[i]%m);
        }
        printf("%d ",ans);
    }
    return 0;
}

相关链接:

Codeforces 题解小全:
https://blog.csdn.net/ZJ_MRZ/article/details/81530091

Codeforces 1017A The Rank 题解:
https://blog.csdn.net/ZJ_MRZ/article/details/81529980

C++模板小站:
https://blog.csdn.net/ZJ_MRZ/article/details/80950647

posted @ 2018-08-07 08:27  ZJ_MRZ  阅读(183)  评论(0编辑  收藏  举报