SGU 127 Telephone directory (模拟)

time limit per test: 0.5 sec. 
memory limit per test: 4096 KB

http://acm.sgu.ru/problem.php?contest=0&problem=127

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

ceil(x / k) = (x - 1) / k + 1 (x!=0)


完整代码:

/*15ms,835KB*/

#include<cstdio>
#include<cmath>

int has[8];

int main(void)
{
	int k, n, count = 2, num;
	scanf("%d%d", &k, &n);
	while (n--)
	{
		scanf("%d", &num);
		if (num < 1000 || num > 7999)
			continue;
		++has[num / 1000];
	}
	for (int i = 1; i < 8; ++i)
		if (has[i])
			count += (has[i] - 1) / k + 1;
	printf("%d", count);
	return 0;
}

Resource: 5th Southern Subregional Contest. Saratov 2002

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值