127. Telephone directory

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

CIA has decided to create a special telephone directory for its agents. The first 2 pages of the directory contain the name of the directory and instructions for agents, telephone number records begin on the third page. Each record takes exactly one line and consists of 2 parts: the phone number and the location of the phone. The phone number is 4 digits long. Phone numbers cannot start with digits 0 and 8. Each page of the telephone directory can contain not more then K lines. Phone numbers should be sorted in increasing order. For the first phone number with a new first digit, the corresponding record should be on a new page of the phone directory. You are to write a program, that calculates the minimal number P pages in the directory. For this purpose, CIA gives you the list of numbers containing N records, but since the information is confidential, without the phones locations.

Input

The first line contains a natural number K (0 < K < 255) - the maximum number of lines that one page can contain. The second line contains a natural N (0 < N < 8000) - number of phone numbers supplied. Each of following N lines contains a number consisting of 4 digits - phone numbers in any order, and it is known, that numbers in this list cannot repeat.

Output

First line should contain a natural number P - the number of pages in the telephone directory.

Sample Input

5
10
1234
5678
1345
1456
1678
1111
5555
6789
6666
5000

Sample Output

5
读题
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
int num[8000];
int main(){
scanf("%d%d",&k,&n);
for(int i=0;i<n;i++)scanf("%d",num+i);
sort(num,num+n);
int page=2;
int st=num[0]/1000;
int nn=0;
for(int i=0;i<n;i++){
if(st==num[i]/1000){
nn++;
}
else {
page+=(nn+k-1)/k;
st=num[i]/1000;
nn=1;
}
}
page+=(nn+k-1)/k;
printf("%d\n",page);
return 0;
}

  

快速切题sgu127. Telephone directory的更多相关文章

  1. SGU 127. Telephone directory --- 模拟

    <传送门> 127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB C ...

  2. 快速切题 poj 1002 487-3279 按规则处理 模拟 难度:0

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 247781   Accepted: 44015 Descr ...

  3. Telephone directory - SGU 127(水)

    题目大意:有一个电话簿,每页最多纪录K行电话,现在有N个电话要记录在电话薄上,要求同页的电话号码的首位要相同,电话簿的前两页是纪录的别的东西,问最少需要多少页电话簿. 分析:直接求首位数字有多少个即可 ...

  4. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  5. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  6. 快速切题 sgu120. Archipelago 计算几何

    120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...

  7. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  8. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  9. 快速切题 sgu117. Counting 分解质因数

    117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...

随机推荐

  1. Python3基础 list 元组转成列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. 第几天|2018年蓝桥杯B组题解析第一题-fishers

    标题:第几天 2000年的1月1日,是那一年的第1天. 那么,2000年的5月4日,是那一年的第几天? 注意:需要提交的是一个整数,不要填写任何多余内容. 思路:计算日期,用excel计算两个日期的差 ...

  3. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0

    Windows 7/8/10机器上安装Python 2.7后,下载一些Package包进行setup时总是报错UnicodeDecodeError,如下: File "C:/Python27 ...

  4. c#之有参和无参构造函数,扩展方法

    例如在程序中创建 Parent类和Test类,在Test有三个构造函数,parent类继承Test类,那么我们可以在Test类自身中添加 扩展 方法吗? 答案:是不可以的.因为扩展方法必须是静态的,且 ...

  5. Unity 之 Time

    Time.deltaTime  指完成每一帧的时间,根据得到实际的测试,可以看到每一帧的所用时间不一致,差距很微小. Time.deltaTime在Update和FixedUpdate中显示的是不一样 ...

  6. Ansible 操作windows

      1.主控端安装ansible         1) pip install ansible 2.主控端安装相关的包 pip install http://github.com/diyan/pywi ...

  7. 51nod 1102 面积最大的矩形(单调栈)

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1102 题意: 思路: 做法就是求出每个长方形向左向右所能延伸的最大距离. ...

  8. Oncomine: 一个肿瘤相关基因研究的数据库--转载

    如果你获得了一个肿瘤差异表达基因,想研究其是否可作为某种肿瘤的潜在标志物和靶点,又怕做实验会得到阴性结果,浪费时间和金钱,这时候你就应该想到Oncomine数据库了(www.oncomine.org) ...

  9. Tomcat下载及配置(windows系统)

    1.去官网下载 下载安装版的直接安装即可,下载解压版(推荐)的往下看. 2.win键+R键,输入sysdm.cpl点击确定,弹出系统属性窗口,选择菜单栏的高级选项卡,然后点击环境变量. 3.在弹出的窗 ...

  10. SPOJ - INTSUB 数学

    题目链接:点击传送 INTSUB - Interesting Subset no tags  You are given a set X = {1, 2, 3, 4, … , 2n-1, 2n} wh ...