zoukankan      html  css  js  c++  java
  • 华中农业大学第五届程序设计大赛网络同步赛-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 }
  • 相关阅读:
    C#创建Windows Service(Windows 服务)基础教程
    c#写windows服务
    怎么样快速学习AngularJS?
    Web API 安全问题
    ASP.NET Web API身份验证和授权
    通过HttpClient来调用Web Api接口~续~实体参数的传递
    在WebApi中实现Cors访问
    SQL Server 动态生成数据库所有表Insert语句
    EasyUI combobox
    Linq使用Group By 1
  • 原文地址:https://www.cnblogs.com/Penn000/p/6756251.html
Copyright © 2011-2022 走看看