*HDU3486 RMQ+二分
Interviewe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6722 Accepted Submission(s): 1592
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?
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.
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.
//RMQ.二分啊老出错
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int peo[];
int dp[][];
void rmq1(int n)
{
for(int i=;i<n;i++)
dp[i][]=peo[i];
for(int j=;(<<j)<=n;j++)
{
for(int i=;i+(<<j)-<n;i++)
dp[i][j]=max(dp[i][j-],dp[i+(<<(j-))][j-]);
}
}
int rmq2(int lef,int rig)
{
int k=;
while(<<(k+)<=rig-lef+) k++;
return max(dp[lef][k],dp[rig-(<<k)+][k]);
}
int main()
{
int n,k;
while(scanf("%d%d",&n,&k))
{
int sum=;
if(n<&&k<) break;
for(int i=;i<n;i++)
{
scanf("%d",&peo[i]);
sum+=peo[i];
}
if(sum<=k)
{
printf("-1\n");
continue;
}
rmq1(n);
int ans=;
int lef=,rig=n,mid;
while(lef<=rig)
{
mid=(lef+rig)>>;
int num=;
int len=n/mid;
for(int i=;i<=mid;i++)
{
num+=rmq2((i-)*len,i*len-);
}
if(num>k)
{
ans=mid;
rig=mid-;
}
else lef=mid+;
}
printf("%d\n",ans);
}
return ;
}
*HDU3486 RMQ+二分的更多相关文章
- hdu 5289 Assignment(2015多校第一场第2题)RMQ+二分(或者multiset模拟过程)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5289 题意:给你n个数和k,求有多少的区间使得区间内部任意两个数的差值小于k,输出符合要求的区间个数 ...
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 【bzoj2500】幸福的道路 树形dp+倍增RMQ+二分
原文地址:http://www.cnblogs.com/GXZlegend/p/6825389.html 题目描述 小T与小L终于决定走在一起,他们不想浪费在一起的每一分每一秒,所以他们决定每天早上一 ...
- HDU 5089 Assignment(rmq+二分 或 单调队列)
Assignment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- 玲珑杯 Round 19 B Buildings (RMQ + 二分)
DESCRIPTION There are nn buildings lined up, and the height of the ii-th house is hihi. An inteval [ ...
- codeforces 487B B. Strip(RMQ+二分+dp)
题目链接: B. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForces 689D Friends and Subsequences (RMQ+二分)
Friends and Subsequences 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/H Description Mi ...
- HDU 5726 GCD (RMQ + 二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 给你n个数,q个询问,每个询问问你有多少对l r的gcd(a[l] , ... , a[r]) ...
- 2016 Multi-University Training Contest 1 GCD RMQ+二分(预处理)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5726 题意:有N(N <= 100,000),之后有Q(Q <= 100,000)个区间查询[ ...
随机推荐
- SQL SERVER 中 GO 的用法
用信号通知 Microsoft® SQL Server™ 实用工具一批 Transact-SQL 语句的结束.GO 不是 Transact-SQL 语句:而是可为 osql 和 isql 实用工具及 ...
- Hadoop概括——学习笔记<一>
之前有幸在MOOC学院抽中小象学院hadoop体验课. 这是小象学院hadoop2.X概述第一章的笔记 第一章主要讲的是hadoop基础知识.老师讲的还是比较全面简单的,起码作为一个非专业码农以及数据 ...
- [Python] 机器学习库资料汇总
声明:以下内容转载自平行宇宙. Python在科学计算领域,有两个重要的扩展模块:Numpy和Scipy.其中Numpy是一个用python实现的科学计算包.包括: 一个强大的N维数组对象Array: ...
- average slice
A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such ...
- PHP判断文件夹是否存在和创建文件夹的方法(递归创建多级目录)
在开始之前,我先说明一下,可能许多朋友与我一样认为只要给一个路径,mkdir就可以创建文件夹,其实不是那样,单个的MKDIR只能创建一级目录,对于多级的就不行了,那如何用mkdir来创建呢?先我抄一段 ...
- 在vs中char类型的实参与LPCWSTR类型的形参类型不兼容怎么解决?
今天在做 COS脚本解释器的时候,遇到了这个问题 先了解一下 LPCTCHAR 这个东东 LPCTSTR用来表示你的字符是否使用UNICODE, 如果你的程序定义了UNICODE或者其他相关的宏,那么 ...
- MariaDB 多主一从 搭建测试
背景: 目前MySQL依然只支持一个Slave从一个Master复制数据,虽然也可以做到一主多备(M->S),双主复制(M<->M)等架构,但是局限性依然很大.由于项目的要求,需要各 ...
- Nodejs学习笔记(十二)--- 定时任务(node-schedule)
目录 写在之前 Cron风格定时器 通配符解释 范围触发 递归规则定时器 对象文本语法定时器 取消定时器 写在之后 写在之前 在实际开发项目中,会遇到很多定时任务的工作.比如:定时导出某些数据.定时发 ...
- 网络知识学习2---(IP地址、子网掩码)(学习还不深入,待完善)
紧接着:网络知识学习1 1.IP地址 IP包头的结构如图 A.B.C网络类别的IP地址范围(图表) A.B.C不同的分配网络数和主机的方式(A是前8个IP地址代表网络,后24个代表主机:B是16 ...
- Linux常用命令学习6---(vim的使用)
先说说我,我使用了这么久的vim,但是完全没有将vim的功能完全利用到,无非就是使用了编辑(i).保存(:w).退出(:q).等简单的编辑,命令,以及NerdTree这一个插件,所以在这里需要重新学习 ...