SGU 127. Telephone directory --- 模拟

<传送门>

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

 【题目大意】

CIA要做一个电话通讯录,通讯录前两页是通讯录的名字和使用说明。
从第三页开始就是正式的通讯录存储。
每条记录占一行,包括电话号码和号码归属地。
每个号码占4位,并且不能用0和8开头。
每页的电话号码条数不能超过K条。
电话号码必须按照升序排序。
如果本页的号码的第一个数字出现新的数字的话,那么就要从下一页开始记录。
写一个程序,计算存储这些号码的最小页数。
但是CIA这个人只给你N个电话号码,并不给你这些电话号码的归属地。(号码不会重复)


K-----一页最多可以存K条
N-----号码总条数

 

【题目分析】

就是一个统计的问题,直接模拟就行。

 

  

 

 

posted @   北岛知寒  阅读(205)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示
主题色彩