*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)个区间查询[ ...
随机推荐
- [Python] 学习笔记之MySQL数据库操作
1 Python标准数据库接口DB-API介绍 Python标准数据库接口为 Python DB-API,它为开发人员提供了数据库应用编程接口.Python DB-API支持很多种的数据库,你可以选择 ...
- PHP函数 addslashes() 和 mysql_real_escape_string() 的区别 && SQL宽字节,绕过单引号注入攻击
首先:不要使用 mysql_escape_string(),它已被弃用,请使用 mysql_real_escape_string() 代替它. mysql_real_escape_string() 和 ...
- 新语言代码高亮及Windows Live Writer插件开发
最近在博客园做一些学习笔记.一个是看apple的swift官方书,另外一个是随学校课堂(SICP)学习scheme. 这两种语言都谈不上普及(或者说swift太新).博客园原来的windows liv ...
- Linux ftp访问控制配置,包括访问ftp权限和访问ftp目录权限
在Linux 上建立用户为website1 home目录是/data/home/website1 但是用ftp登录以后,路径可以随便切换,并且可以进入别的站点下 进行增.删.改 本篇的目的是:在lin ...
- C#获取命令行输出内容的方法
获取命令行输出内容的方式有传统和异步两种方式. 传统方式: public static void RunExe(string exePath, string arguments, out string ...
- 提取刷机包内system.new.dat文件
转换 使用python脚本sdat2img来完成 sdat2img.py system.transfer.list system.new.dat system.img 输出信息 Skipping co ...
- .NET程序员转Java不完全指南
首先要声明一点,“转”字并不包含那种语言牛B的意思. 然后要声明一点,“转”字仅限于企业应用开发的语言的转. 假设各种数据库切换无代沟, 假设各种WEB客户端技术无障碍. 1.搭建环境,IDE主流是e ...
- java学习第四天 类和变量
java也属于面向对象的编程 面向对象的三大特征: 封装 继承 多态 类 对象 对象:真实存在的唯一的事物 面向对象编程(oop)思想力图使对计算机语言中的事物的描述和自然界中的事物尽可能保持一致 ...
- (转)CDN——到底用还是不用?
用CDN的七个理由 浏览器从服务器上下载css.js和图片等文件时都要和服务器连接,而大部分浏览器对同一个域名用于下载文件的并发连接数限制在4个,这意味着如果要下载第五个文件就必须等前四个文件中有一个 ...
- thinkphp全站静态页实现方法!
1:在根目录下的全局index.php中加下面这行: define('HTML_PATH', './htm');//生成静态页面的文件位置 2:在项目的配置文件config.php中加下面这行: 'H ...