人生中第一次写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;
}

HDOJ 3486 Interviewe的更多相关文章

  1. hdu 3486 Interviewe (RMQ+二分)

    Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. HDU 3486 Interviewe

    题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...

  3. HDU 3486 Interviewe RMQ

    题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...

  4. 3486 ( Interviewe )RMQ

    Problem Description YaoYao has a company and he wants to employ m people recently. Since his company ...

  5. [数据结构]RMQ问题小结

    RMQ问题小结 by Wine93 2014.1.14   1.算法简介 RMQ问题可分成以下2种 (1)静态RMQ:ST算法 一旦给定序列确定后就不在更新,只查询区间最大(小)值!这类问题可以用倍增 ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  8. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

随机推荐

  1. 释放C盘空间的27招优化技巧

    主要讲讲Windows操作系统在C盘空间不足的情况下,我们可以通过那些具体手段来增加C盘空间. 1.打开"我的电脑"-"工具"-"文件夹选项" ...

  2. mysql Unknown table engine 'InnoDB'解决办法

    最近做项目时,由于数据库存的中文乱码.改了一下配置.中文乱码改过来了,但是在导入数据时Unknown table engine 'InnoDB'  百度上各种拷贝.最后看了下InnoDB.是一种支持事 ...

  3. C语言如何 实现 下雪效果

    题外话  前言 1.本文主要围绕 如何 在 控制台上 下起 一场 只有自己能看见的雪 2.是个简易跨平台的,主要是C语言 3.动画 采用 1s 40帧, 雪花具有 x轴速度和y轴速度 4.比较简单,可 ...

  4. 为了android sdk下载,必须修改hosts

    #Download 下载 203.208.46.146 dl.google.com 203.208.46.146 dl-ssl.google.com #Groups 203.208.46.146 gr ...

  5. sk_buff

    在2.6.24之后这个结构体有了较大的变化,此处先说一说2.6.16版本的sk_buff,以及解释一些问题. 一. 先直观的看一下这个结构体~~~~~~~~~~~~~~~~~~~~~~在下面解释每个字 ...

  6. b75,gtx560,I5 安装10.10.2

    1.安装变色龙,wowpc.iso,这个是可以让电脑从windows引导 mac 安装的. 2.把黑苹果CDR压到一个硬盘分区里去. 3.安装10.10.2,把安装盘里的extra拷贝到 系统盘里 , ...

  7. 归并排序 & 计数排序 & 基数排序 & 冒泡排序 & 选择排序 ----> 内部排序性能比较

    2.3 归并排序 接口定义: int merge(void* data, int esize, int lpos, int dpos, int rpos, int (*compare)(const v ...

  8. LoadRunner - 实战,转发

    最近几天一直在读代震军的博客,他是Discuz!NT的设计者,读了他的一系列关于 Discuz!NT的架构设计文章,大呼过瘾,特别是Discuz!NT在解决高访问高并发时所设计的一系列方案,本人尤其感 ...

  9. java 静态变量生命周期(类生命周期)

    Static: 加载:java虚拟机在加载类的过程中为静态变量分配内存. 类变量:static变量在内存中只有一个,存放在方法区,属于类变量,被所有实例所共享 销毁:类被卸载时,静态变量被销毁,并释放 ...

  10. C++设计模式——工厂方法模式

    本文版权归果冻说所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.» 本文链接:http://www.jellythink.com/arch ...