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. P2709 小B的询问

    题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重 ...

  2. swift设计模式学习 - 原型模式

    移动端访问不佳,请访问我的个人博客 设计模式学习的demo地址,欢迎大家学习交流 原型模式 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 定义 用原型实例指定创建对象的种类,并且通 ...

  3. C#用Linq查询Combox的数据源

    https://www.cnblogs.com/sufei/archive/2010/01/12/1645763.html var result =  ((DataTable) (this.ComSh ...

  4. 论文笔记——Deep Model Compression Distilling Knowledge from Noisy Teachers

    论文地址:https://arxiv.org/abs/1610.09650 主要思想 这篇文章就是用teacher-student模型,用一个teacher模型来训练一个student模型,同时对te ...

  5. python 集合的运算

    x = frozenset([, , , , ]) y = frozenset([, , , , ]) #如果x与y没有公共元素,返回true print(x.isdisjoint(y)) #返回x与 ...

  6. quality center 支持的平台

  7. C# 二进制字符串互转

    1.字符转二进制 public static string ChineseToBinary(string s) { byte[] data = Encoding.Unicode.GetBytes(s) ...

  8. WM_COPYDATA

    1. WM_COPYDATA : https://msdn.microsoft.com/en-us/library/windows/desktop/ms649011(v=vs.85).aspx COP ...

  9. Qt5.3.2_CentOS6.4(x86)_代码文件编码

    1.1.1.Qt5.3.2_MinGW 在Windows中安装时,默认的文件编码是 UTF8. 1.2.在 CentOS6.4中安装 qt-opensource-linux-x86-5.3.2.run ...

  10. [ios][swift]UIButton

    参考:http://www.hangge.com/blog/cache/detail_529.html