zoukankan      html  css  js  c++  java
  • 快速切题sgu127. Telephone directory

    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;
    }
    

      

  • 相关阅读:
    Socket Client & Server
    2台整机,多线程运行测试时间不稳定
    去了一趟宝马铁西工厂,才知道工厂已经在数字孪生
    窗帘电机测试系统调试心得
    AntDesignBlazor 学习笔记
    简单粗暴的实现 Blazor Server 登录鉴权
    Blazor 子组件与父组件通过 ChildEvents 传递数据的方法
    EasyExcel 列 固定下拉选项的做法
    Java代码在数据库存取某些敏感字段的加解密做法
    nacos 使用【一】 创建一个属于自己的配置空间
  • 原文地址:https://www.cnblogs.com/xuesu/p/4008896.html
Copyright © 2011-2022 走看看