• 华中农业大学第五届程序设计大赛网络同步赛-K


    K.Deadline

    There are N bugs to be repaired and some engineers whose abilities are roughly equal. And an engineer can repair a bug per day. Each bug has a deadline A[i].

    Question: How many engineers can repair all bugs before those deadlines at least? 1<=n<= 1e6. 1<=a[i] <=1e9

    Input

    Description There are multiply test cases. In each case, the first line is an integer N , indicates the number of bugs. The next line is n integers indicates the deadlines of those bugs.

    Output

    Description There are one number indicates the answer to the question in a line for each case.

    Input

    4 1 2 3 4

    Output

    1

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 const int N = 1000005;
     9 int a, book[N], day[N];
    10 
    11 int main()
    12 {
    13     int n;
    14     while(scanf("%d", &n)!=EOF)
    15     {
    16         int len = 0;
    17         memset(book, 0, sizeof(book));
    18         memset(day, 0, sizeof(day));
    19         for(int i = 0; i < n; i++)
    20         {
    21             scanf("%d", &a);
    22             if(a <= n)
    23               book[a]++;
    24             if(a < n && a > len)len = a;
    25         }
    26         int ans = 1;
    27         for(int i = 1; i <= len; i++)
    28         {
    29             while(book[i]){
    30                 bool fg = false;
    31                 for(int j = 1; j <= ans; j++){
    32                     if(day[j] < i){
    33                         book[i]--;
    34                         day[j]++;
    35                         fg = true;
    36                         break;
    37                     }
    38                 }
    39                 if(!fg){
    40                     ans++;
    41                     day[ans]++;
    42                     book[i]--;
    43                 }
    44             }
    45         }
    46         printf("%d
    ", ans);
    47     }
    48 
    49     return 0;
    50 }
  • 相关阅读:
    什么是 Spring Boot?
    Spring Cloud Gateway?
    什么是 Netflix Feign?它的优点是什么?
    SpringBoot和SpringCloud的区别?
    什么是Hystrix?
    什么是Spring Cloud Bus?
    什么是Ribbon?
    eureka自我保护机制是什么?
    spring cloud 和dubbo区别?
    如何在 Spring Boot 中禁用 Actuator 端点安全性?
  • 原文地址:https://www.cnblogs.com/Penn000/p/6756251.html
Copyright © 2020-2023  润新知