人生中第一次写RMQ。。。。
一看就知道 RMQ+2分
但是题目文不对题。。。。不知道到底在问什么东西。。。。
各种WA,TLE,,RE。。。后就过了
果然无论错成什么样都可以过的,就是 上层的样例 啊 

Interviewe

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3865    Accepted Submission(s): 956

Problem Description
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there are n people coming for the interview. However, YaoYao is so busy that he has no time to interview them by himself. So he decides to select exact m interviewers for this task.
YaoYao decides to make the interview as follows. First he queues the interviewees according to their coming order. Then he cuts the queue into m segments. The length of each segment is , which means he ignores the rest interviewees (poor guys because they comes late). Then, each segment is assigned to an interviewer and the interviewer chooses the best one from them as the employee.
YaoYao’s idea seems to be wonderful, but he meets another problem. He values the ability of the ith arrived interviewee as a number from 0 to 1000. Of course, the better one is, the higher ability value one has. He wants his employees good enough, so the sum of the ability values of his employees must exceed his target k (exceed means strictly large than). On the other hand, he wants to employ as less people as possible because of the high salary nowadays. Could you help him to find the smallest m?
 

Input
The input consists of multiple cases.
In the first line of each case, there are two numbers n and k, indicating the number of the original people and the sum of the ability values of employees YaoYao wants to hire (n≤200000, k≤1000000000). In the second line, there are n numbers v1, v2, …, vn (each number is between 0 and 1000), indicating the ability value of each arrived interviewee respectively.
The input ends up with two negative numbers, which should not be processed as a case.
 

Output
For each test case, print only one number indicating the smallest m you can find. If you can’t find any, output -1 instead.
 

Sample Input
11 300
7 100 7 101 100 100 9 100 100 110 110
-1 -1
 

Sample Output
3
Hint

We need 3 interviewers to help YaoYao. The first one interviews people from 1 to 3, the second interviews people from 4 to 6, and the third interviews people from 7 to 9. And the people left will be ignored. And the total value you can get is 100+101+100=301>300.

 

Source
 

Recommend
zhengfeng
 

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,k;
int m;
int v[200020];
int dp[200020][33];
int ans=-1;
void RMQ_init()
{
    for(int i=1;i<=n;i++) dp[0]=v;
    for(int j=1;(1<<j)<=n;j++)
    {
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
            int m=i+(1<<(j-1));
            dp[j]=max(dp[j-1],dp[j-1]);
        }
    }
}
int RMQ(int L,int R)
{
    int k=0;
    while((1<<(k+1))<=R-L+1) k++;
    return max(dp[L][k],dp[R-(1<<k)+1][k]);
}
int isOK(int m)
{
    int sum=0;
    int len=n/m;
    for(int i=1;i<=m;i++)
    {
        sum+=RMQ(len*(i-1)+1,i*len);
     //   if(sum>k) ans=i/m;
 //       cout<<"("<<i<<","<<i+m-1<<")     ";
    }
 //   cout<<"---->"<<sum<<endl;
    if(sum>k) return 1;
    else return 0;
}
int main()
{
while(cin>>n>>k)
{
    ans=-1;
    if(n<0&&k<0) break;
    memset(v,0,sizeof(v));
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
        cin>>v;
    int mi=1;
    int ma=n;
    RMQ_init();
    while(mi<=ma)
    {
 //       cout<<mi<<","<<ma<<"=:";
        int md=mi+(ma-mi)/2;
 //       cout<<isOK(md)<<endl;
        if(isOK(md))
        {
            ans=md;
            ma=md-1;
        }
        else
        {
            mi=md+1;
        }
    }
    cout<<ans<<endl;
/*
   for(int i=0;i<=n+1;i++)
   {
       for(int j=0;(1<<j)<=n;j++)
        cout<<dp[j]<<" ";
       cout<<endl;
   }
   int a,b;
   while(cin>>a>>b)
   {
       cout<<RMQ(a,b)<<endl;
   }
*/
}
    return 0;
}

最新文章

  1. JSON学习
  2. python学习之安装模块
  3. Azure DW
  4. cocos2d-x在Android平台下的音频导致的卡死
  5. 20. 求阶乘序列前N项和
  6. 进程间的通讯(IPC)方式
  7. js实现checkbox的全选/取消
  8. SQLSERVER一些公用DLL
  9. angular2项目添加ng2-bootstrap
  10. 前端MVC Vue2学习总结(六)——axios与跨域HTTP请求、Lodash工具库
  11. java.util.zip.ZipException:ZIP file must have at least one entry
  12. leetCode(66)-Excel Sheet Column Title
  13. 基于expressjs老项目的翻新方案
  14. Window安装Redis并设置为开机启动
  15. redgate的mysql架构比较和数据比较工具
  16. Android之MVC模式的使用
  17. TYVJ P1933 绿豆蛙的归宿 题解(未完成)
  18. framework7的改进,以及与vue组合使用遇到的问题以及解决方法 (附vue的原理)
  19. fn project Message Queues 配置
  20. Ubuntu16.04 ARM平台移植libcurl curl-7.63.0

热门文章

  1. 【Delphi】注册快捷键
  2. PHP实例 表单数据插入数据库及数据提取 用户注册验证
  3. .Net并行编程
  4. 配置php5.6的运行环境
  5. kettle发送邮件
  6. angularjs+nodejs+mongodb三件套
  7. centos rsync安装配置
  8. iOS学习之UITabBarController
  9. ios各种手势,很有意思
  10. OC开发中运用到的枚举