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 }
  • 相关阅读:
    《Linux C一站式学习》第七章 结构体
    《Linux C一站式学习》第三章 简单的函数
    《Windows程序设计》第一章 起步
    CSS在线课程学习笔记
    《Windows程序设计》第三章 窗口和消息
    window.open与window.showModalDialog中主页面与从页面间的通信(原创) 中庸
    php文件实现将大文件导入到mysql数据库中
    我为何爱读代码?你为何也应当爱?
    解决phpMyAdmin导入mysql数据库超过2M的问题
    对linux交换分区swap的一些认识总结
  • 原文地址:https://www.cnblogs.com/tingtin/p/9377530.html
Copyright © 2011-2022 走看看