SGU - 127 - Telephone directory (水~)
来源:互联网 发布:mac软件开发 常用工具 编辑:程序博客网 时间:2024/06/06 00:56
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
5101234567813451456167811115555678966665000
Sample Output
5
Author: Alex Y. Suslov, Victor G. Samoilov, Natalia L. AndreevaResource: 5th Southern Subregional Contest. Saratov 2002Date: 2002-10-10
这个题就是去找有多少页电话薄
按电话开头那个数字分开,任何一个数字开头的数的数目多于k时,页数加一
AC代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int k, n;while(scanf("%d %d", &k, &n) != EOF){int ans = 0, a[11], w;memset(a, 0, sizeof(a));for(int i=1; i<=n; i++){scanf("%d", &w);a[w/1000]++;}for(int i=1; i<10; i++){if(a[i]){ans++;ans+=(a[i] - 1) / k;}}printf("%d\n", ans+2);}return 0;}
- SGU - 127 - Telephone directory (水~)
- SGU 127 Telephone directory(水~)
- SGU 127 Telephone directory
- sgu 127 Telephone directory
- SGU 127 Telephone directory (模拟)
- [SGU]127. Telephone directory
- SGU127-Telephone directory
- sgu127:Telephone directory
- SGU127 Telephone directory
- Telephone
- SGU 115 Calendar(水~)
- SGU 133 Border(水~)
- SGU 142 Keyword(水~)
- SGU 144 Meeting(水~)
- SGU - 403 - Scientific Problem (水)
- SGU 100 A+B(水~)
- SGU 114 Telecasting station(水~)
- SGU 123 The sum(水~)
- 快速提高 Vi/Vim 使用效率的原则与途径
- ray ban sunglasses vJT3B 8ORD QRGD
- alsa lib和utils工具包移植总结
- ScrollView 代理
- 第十七周 项目四--日期结构体(1)-该年的第几天
- SGU - 127 - Telephone directory (水~)
- 随笔
- MySQL行级锁、表级锁、页级锁详细介绍
- C 语言程序设计实践 8.1 字符串
- ARM 中断状态和SVC状态的堆栈切换 (异常)
- C 语言程序设计实践 8.2 W.C之十个问题
- 阅读笔记—电商应用设计的九大条例
- Win7x64系统下Synplify正常工作的一种解决方法
- MySQL存储引擎MyISAM与Innodb的那些事