<传送门>

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;
}

  

SGU 127. Telephone directory --- 模拟的更多相关文章

  1. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  2. Telephone directory - SGU 127(水)

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

  3. SGU 分类

    http://acm.sgu.ru/problemset.php?contest=0&volume=1 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traff ...

  4. 今日SGU 5.4

    SGU 127 题意:给你n个数字,和m,k,问你有多少个数字的m次幂可以被k整除 收获:快速幂 #include<bits/stdc++.h> #define de(x) cout< ...

  5. Active Directory 域服务(AD DS)

    本文内容 概述 工作组架构与域架构 名称空间(Namespace) 对象(Object).容器(Container)与组织单位(Organization Units,OU) 域树(Domain Tre ...

  6. 今日SGU 5.3

    SGU 107 题意:输入一个N,表示N位数字里面有多少个的平方数的结尾9位是987654321 收获:打表,你发现相同位数的数相乘结果的最后几位,就和那两个相乘的数最后几位相乘一样,比如3416*8 ...

  7. AD 域服务简介(一)- 基于 LDAP 的 AD 域服务器搭建及其使用(转)

    一.前言 1.1 AD 域服务 什么是目录(directory)呢? 日常生活中使用的电话薄内记录着亲朋好友的姓名.电话与地址等数据,它就是 telephone directory(电话目录):计算机 ...

  8. win2008 ad域控搭建

    一.前言 1.1 AD 域服务 什么是目录(directory)呢? 日常生活中使用的电话薄内记录着亲朋好友的姓名.电话与地址等数据,它就是 telephone directory(电话目录):计算机 ...

  9. C++ STL初学笔记

    C++  STL初学笔记 更系统的版本见徐本柱的PPT set 在这儿:http://www.cnblogs.com/pdev/p/4035020.html #include <vector&g ...

随机推荐

  1. go中的字符串数值转化

    #string到int int,err := strconv.Atoi(string) #string到int64 int64, err := strconv.ParseInt(string, 10, ...

  2. JS的ES6的class

    1.类的创建: 定义类 类的构造函数 类的静态方法 类的一般属性和方法 //定义类 class Person{ // 类的静态方法,相当于Person.test = function(){consol ...

  3. MySQL 8.0 以上版本重置 root 用户密码的终极办法

    1. 在 /etc/my.cnf 文件末尾追加 skip-grant-tables [root@abdefg mysql]# vim /etc/my.cnf [mysql] # 设置mysql客户端默 ...

  4. Django 基础篇(二)视图与模板

    视图 在django中,视图对WEB请求进行回应 视图接收reqeust对象作为第一个参数,包含了请求的信息 视图就是一个Python函数,被定义在views.py中 #coding:utf- fro ...

  5. matlab 只安装部分产品

  6. 洛谷P2607题解

    想要深入学习树形DP,请点击我的博客. 本题的DP模型同 P1352 没有上司的舞会.本题的难点在于如何把基环树DP转化为普通的树上DP. 考虑断边和换根.先找到其中的一个环,在上面随意取两个点, 断 ...

  7. Centos pip 安装uwsgi 报错“fatal error: Python.h: No such file or directory”

    解决方法: 安装python-devel即可,注意,不是python-dev yum -y install python-devel

  8. 【转】vim复制与粘贴

    用vim写代码时,经常遇到这样的场景,复制多行,然后粘贴. 这样做:1. 将光标移动到要复制的文本开始的地方,按v进入可视模式.2. 将光标移动到要复制的文本的结束的地方,按y复制.此时vim会自动将 ...

  9. Tesserac初探

    安装Tesseract Windows 系统 下载可执行安装文件https://code.google.com/p/tesseract-ocr/downloads/list安装.或者https://d ...

  10. 使用innobackupex进行mysql的差异备份还原和延迟复制

    使用innobackupex进行mysql的差异备份还原和延迟复制 背景: 有同事执行update语句没有添加where条件,导致大量脏数据,需要将这张表恢复到前一天 数据库上有备份,每周一次完整备份 ...