<传送门>

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-----号码总条数

【题目分析】

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

//Memory   Time
// K MS
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<iomanip>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main()
{
// freopen("cin.txt","r",stdin);
// freopen("cout.txt","w",stdout);
int K,N;
int cnt[10];
cin>>K>>N;
char str[10];
memset(cnt,0,sizeof(cnt));
for(int i=0;i<N;i++)
{
scanf("%s",str);
getchar();
cnt[str[0]-'0']++;
} int page=0;
for(int i=0;i<10;i++)
{
if(cnt[i]%K==0)
{
page+=cnt[i]/K;
}
else
{
page+=cnt[i]/K+1;
}
}
cout<<page+2<<endl;
return 0;
}

  

最新文章

  1. 将webservice封装成dll
  2. About memories in ASIC FPGA
  3. Android接收短信
  4. Android问题-打开DelphiXE8与DelphiXE10编译空工程提示“[Exec Error] The command exited with code 1.”
  5. Java笔记:String类
  6. hdu_2871_Memory Control(巨恶心线段树)
  7. CNN压缩:为反向传播添加mask(caffe代码修改)
  8. EasyUI Datagrid 鼠标悬停显示单元格内容 复制代码
  9. Tomcat初应用
  10. [转]另一种遍历Map的方式: Map.Entry 和 Map.entrySet()
  11. Mybatis入门程序
  12. java加密算法AES与RSA
  13. Python 上下文管理协议中的__enter__和__exit__基本理解
  14. 关于Servlet的一些归纳(2)
  15. django之信号
  16. 用JDOM和DOM4J解析节点名节点值
  17. cocos2dx自带物理引擎-创建物理世界
  18. hdu-5985 概率DP
  19. 5-java 排序, sort, collections.sort()
  20. go语言练习:sha256、sha512哈希算法

热门文章

  1. Linux定时任务crontab命令
  2. UFUN 函数 UF_UI UF_DISP函数( UF_UI_select_with_class_dialog 、UF_DISP_set_highlight)
  3. day 11
  4. ZROI 2020WC集训训练赛 Day4
  5. iptables 端口转发--内网实现上网
  6. java实现开根号的运算
  7. Gamma阶段第五次scrum meeting
  8. DNS基本操作详解
  9. IIS 7中添加匿名访问FTP站点
  10. 【转】Android root检测方法总结