<传送门>

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. [Algorithm] 350. Intersection of Two Arrays II

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  2. BZOJ 4903: [Ctsc2017]吉夫特 数论+dp

    思路很巧妙的一道题 ~ 这个应该不完全是正解,复杂度约为 $O(3\times 10^8)$,有时间再研究研究正解. 首先,最裸的暴力是按照权值从小到大枚举每一个数,然后枚举后面的数来更新方案数,是 ...

  3. django的惰性查询

    django中的查询,在写好查询条件之后,在不调用变量的时候,sql是不会执行的,只有在调用变量的时候,才回去执行, 在一次查询之后,会把变量放进内存,下次再使用这个变量的时候就会使用内存汇总的值. ...

  4. JavaScript 中 call()、apply()、bind() 的用法

    "use strict"; ; var obj = { name:'小李', age:, getInfo(from, to) { console.log(arguments) co ...

  5. Maven配置文件setting.xml详解

    注:本文来源于:大话JAVA的那些事 <Maven配置文件setting.xml详解> <?xml version="1.0" encoding="UT ...

  6. .NET 爬虫总结

    前言 技术本身并无罪,罪恶本质在于人心,好比厨师手中的菜刀用来创造美味佳肴,而杀手手上的刀却用来创造无限的罪恶. 环境 win7 IIS 6.0  SQLserver2012 .NET 4.0 win ...

  7. In Vitro model验证 | Harnessing single-cell genomics to improve the physiological fidelity of organoid-derived cell types

    Transcriptional benchmarking of in vitro cells to in vivo with single-cell rna-seq - 简介 Harnessing s ...

  8. docker使用dnnmmp安装gocron

    使用dnnmmp安装mysql和phpmyadmin默认使用dnnmmp_default网络,因为在安装其他依赖mysql的应用时,需指定网络 ,同时需指定mysql名称 原命令: docker ru ...

  9. cesium地形瓦片(Quantized-mesh)格式

    目录 1.切片规则 2.瓦片格式分析 2.1.数据头部 2.顶点数据 2.3.索引数据 2.4.扩展数据 参考资料: quantized-mesh-1.0 terrain format(用于三维可视化 ...

  10. str.replace替换变量名的字符串

    网易云课堂该课程链接地址 https://study.163.com/course/courseMain.htm?share=2&shareId=400000000398149&cou ...