*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)个区间查询[ ...
随机推荐
- Ubuntu操作系统下软件的卸载
1.查找安装文件列表 $ dpkg --list 2. 将列表名录复制粘贴到文本文件中 3. 搜索关键词,找到准确的名称 4. 在终端中执行命令: $ sudo apt-get --purge rem ...
- D3.js学习记录
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java Native Interface 编程系列一
本文是<Java Native Interface Programmer's Guide and Specification>的读书笔记 Java Native Interface可以让编 ...
- sql select 综合运用
1 : 多个表联合查询 select j.id, jt.Name, j.ApproveType , j.ProductCode, j.Cu ...
- bzoj1023: [SHOI2008]cactus仙人掌图
学习了一下圆方树. 圆方树是一种可以处理仙人掌的数据结构,具体见这里:http://immortalco.blog.uoj.ac/blog/1955 简单来讲它是这么做的:用tarjan找环,然后对每 ...
- edghasdz
匹配2016年10月8日19时51分50秒匹配 可以使用
- jstl fortokens 分割字符串
forTokens标签: forTokens标签用来截取字符串: 属性: * var :定义变量 * items :切分字符串 * begin :从哪开始 * end :到哪结束 * step :步长 ...
- mount挂载问题
安装nfs-utils即可
- Huffman树实现_详细注释
//最优二叉树 #include <iostream> #include <iomanip> using namespace std; //定义结点类型 //[weight | ...
- pm2无法自动重启
在服务器上有个上传文件的服务,之前是pm2启动,每当有文件上传会自动重启 现在为了应对服务器宕机,我把启动脚本放在了另一文件夹内,所以就无法自动重启, 原文在 http://pm2.keymetric ...