sgu 127 Telephone directory
2012-11-01 00:38
399 查看
127. Telephone directory
time limit per test: 0.5 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<iostream> #include<cstring> #include<cstdio> #include<set> #include<algorithm> #include<vector> #include<cstdlib> #define inf 0xfffffff #define CLR(a,b) memset((a),(b),sizeof((a))) using namespace std; int const nMax = 4000; typedef int LL; typedef pair<LL,LL> pij; int a[10]; char s[20]; int k,n; int main(){ scanf("%d",&k); scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%s",s); a[s[0]-'0']++; } int ans=2; for(int i=1;i<10;i++){ if(i==8)continue; ans+=a[i]/k; if(a[i]%k)ans++; } printf("%d\n",ans); return 0; }
相关文章推荐
- SGU 127 Telephone directory(水~)
- SGU - 127 - Telephone directory (水~)
- SGU 127 Telephone directory (模拟)
- SGU 127
- Telephone directory - SGU 127(水)
- sgu 135 + 184 +117+126+114+118+127
- SGU 127 Telephone directory
- SGU127-Telephone directory
- 我自己写的一点sgu题解
- 无法启动world wide web publishing service服务 错误:127 找不到指定的程序的问题
- [SGU 107]987654321 problem (数论)
- - 1 + 2^7 = 127 这样的算式有多少个?
- IIS错误127:找不到指定的程序
- sgu 107. 987654321 problem
- 为什么带符号的8位二进制数是-128~127啊!而不是-127~127啊!
- IIS无法启动,错误代码127[转自Alibaba DBA Team]
- java byte类型为什么是(127—— -128)
- 高精度——sgu112
- SGU102
- SGU 106 The equation