zoukankan      html  css  js  c++  java
  • Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you've concluded that the system was overloaded; it looks like it couldn't handle the hailstorm of incoming requests. Since the incident, you have had ample opportunity to add more servers to your system, which would make it capable of handling more concurrent requests. However, you've simply been too lazy to do it—until now. Indeed, you shall add all the necessary servers . . . very soon!

    To predict future requests to your system, you've reached out to the customers of your service, asking them for details on how they will use it in the near future. The response has been pretty impressive; your customers have sent you a list of the exact timestamp of every request they will ever make!

    You have produced a list of all the nn upcoming requests specified in milliseconds. Whenever a request comes in, it will immediately be sent to one of your servers. A request will take exactly 10001000 milliseconds to process, and it must be processed right away.

    Each server can work on at most kk requests simultaneously. Given this limitation, can you calculate the minimum number of servers needed to prevent another system breakdown?

    Input Format

    The first line contains two integers 1 le n le 100 0001n100000 and 1 le k le 100 0001k100000, the number of upcoming requests and the maximum number of requests per second that each server can handle.

    Then follow nn lines with one integer 0 le t_i le 100 0000ti100000 each, specifying that the ii-th request will happen t_itimilliseconds from the exact moment you notified your customers. The timestamps are sorted in chronological order. It is possible that several requests come in at the same time.

    Output Format

    Output a single integer on a single line: the minimum number of servers required to process all the incoming requests, without another system breakdown.

    样例输入1

    2 1
    0
    1000

    样例输出1

    1

    样例输入2

    3 2
    1000
    1010
    1999

    样例输出2

    2

    题目来源

    Nordic Collegiate Programming Contest 2015​

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <vector>
     5 #include <string>
     6 #include <string>
     7 #include <map>
     8 #include <cmath>
     9 #include <algorithm>
    10 using namespace std;
    11 const int N=1e5+9;
    12 int t[N];
    13 int n,k;
    14 int MAX,ans;


    //举个例子
    // n=7 k=3
    // 1000 1010 1090 2000 2080 2089 3010
    // 3 3 4 3 3 2 1
    // 1 1 2
    15 int main() 16 { 17 scanf("%d%d",&n,&k); 18 for(int i=0;i<n;i++) 19 scanf("%d",&t[i]); 20 MAX=0; 21 int i,j; 22 for(i=0,j=0;i<n&&j<n;) 23 { 24 while(t[j]-t[i]<1000&&j<n) j++; 25 if(j==n) break; 26 MAX=max(MAX,j-i);//一秒应该处理的请求数目,大于k时,1个机器就不够了。 27 i++; 28 } 29 MAX=max(MAX,j-i); 30 ans=MAX/k; 31 if(MAX%k) ans++;//不能整除就必须要在加一个。 32 printf("%d ",ans); 33 return 0; 34 }
  • 相关阅读:
    关于BehaviorEditorPart 不显示的问题(出自msdn)
    webpart msdn 的位置
    Visual Studio 2008 具有一些新的报表功能和改进之处
    .NET Framework 类库
    Reporting Service 安装 及相关问题如:授予的权限不足解决办法
    单服务器部署&&双服务器部署
    Windows Server 2003安装完毕后汉字都为乱码“方框”,配置域控制器
    Dreamweaver MX显示汉字为乱码的解决方法
    名称以无效字符开头。处理资源 'http://localhost/发布了的/Default.aspx' 时出错。第 1 行,位置: 2
    【随感】my feeling about Long Ying
  • 原文地址:https://www.cnblogs.com/tingtin/p/9377530.html
Copyright © 2011-2022 走看看