码迷,mamicode.com
首页 > 其他好文 > 详细

CF 54A

时间:2016-05-01 23:02:55      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

Description

The Hedgehog likes to give presents to his friend, but no less he likes to receive them.

Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?

In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle:

  • on each holiday day the Hedgehog will necessarily receive a present,
  • he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day).

For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today‘s day is zero, and you should regard today‘s present as already given (i.e., you shouldn‘t count it in the answer).

Input

The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N).

The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.

Output

Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.

大意是收到礼物的规则为每个假日必收到一份礼物,每K天里至少收到一份礼物,求出N天中收到的礼物的最小数量。做法是将N天根据假日所在天数分为一段段,当假日与假日之间间隔天数hol[i]>-hol[i-1]-1>=k时,这段间隔内还至少收到(hol[i]>-hol[i-1]-1)/k份礼物。注意第一个假日与第一天求解,最后一个假日与最后一天求解。

#include<iostream>
#include<cstring>
int hol[400];
using namespace std;
int main()
{
    int n,k,c;
    while(cin>>n>>k)
    {
        memset(hol,0,sizeof(hol));
        cin>>c;
        int sum=0;
        sum+=c;
        if(c!=0)
        {
            cin>>hol[0];
            if(hol[0]-1>=k)
            {
                sum+=(hol[0]-1)/k;
            }
            for(int i=1;i<c;i++)
            {
                cin>>hol[i];
                if(hol[i]-hol[i-1]-1>=k)
                {
                    sum+=(hol[i]-hol[i-1]-1)/k;
                }
            }
            if(n-hol[c-1]>=k)
            {
                sum+=(n-hol[c-1])/k;
            }
        }
        else   //没有假日的情况
        {
                sum+=n/k;    
        }
        cout<<sum<<endl;
    } 
    
    return 0;
} 

 

 

CF 54A

标签:

原文地址:http://www.cnblogs.com/LinesYao/p/5451404.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!