题意:

  瑶瑶有一家有一家公司,最近他想招m个人。因为他的公司是如此的出名,所以有n个人来参加面试。然而,瑶瑶是如此忙,以至于没有时间来亲自面试他们。所以他准备选择m场面试来测试他们。

  瑶瑶决定这样来安排面试。首先,他把这些面试者按照来到的顺序排成一队。然后,他把这个队列切成m段。每段的长度是[n/m](向下取整),这意味着他将忽略掉剩下的人。然后,他将选择每一段里面最好的那个人。

  瑶瑶的想法看起来很有趣,但是他遇到了另外的问题。他把每个人的能力赋了一个值。值越大的越好。他希望员工足够的好,这样,他们的和可以达到他的目标k(严格大于)。另一方面,因为现在高昂的工资,他希望员工的数量尽可能少。

  你能帮他找出最小的m吗?

思路:

  Sparse Table + 枚举区间长度。

  枚举区间个数会TLE,不懂为什么,代码也有点没看懂。

代码:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath> using namespace std; const int MAXN = (int)2e5+; int ST[][MAXN]; //Sparse Table
int hight[MAXN];
int n, k; inline int topBit(int x) {
return (int) (log((double)x)/log(2.0));
} inline int Query(int L, int R) {
int h = hight[R-L];
if ((R-L) < (<<h)) h -= ;
return max(ST[h][L], ST[h][R-(<<h)]);
} int main() {
#ifdef Phantom01
freopen("CSU1364.in", "r", stdin);
#endif // Phantom01 memset(hight, , sizeof(hight));
for (int i = ; i < MAXN; i++) //比他左位移一位的数高一
hight[i] = hight[i>>] + ; while (scanf("%d %d", &n, &k)!=EOF) {
if (-==n && -==k) break; for (int i = ; i < n; i++)
scanf("%d", &ST[][i]); //最下面一层就是原始数据 int h = hight[n];
for (int i = ; i <= h; i++) {
for (int j = ; j < n; j++) {
if ((j+(<<(i-))) < n)
ST[i][j] = max(ST[i-][j], ST[i-][j+(<<(i-))]);
else
ST[i][j] = ST[i-][j];
}
}
int ans = -;
for (int i = n; i > ; i--) {
int m = n/i;
int tmp = ;
for (int j = ; j < m; j++) {
tmp += Query(j*i, (j+)*i);
if (tmp>k) {
ans = j+; //不知道这里为啥是j+1而不是 m
break;
}
}
if (tmp > k)
break;
}
printf("%d\n", ans);
} return ;
}

-------------------------

PS: 后来看到一个代码,直接二分答案即可,复杂度也是n*log(n)的,但是编程复杂度没这么大。

 #include <cstdio>

 int a[], n;

 bool Can(int m, int k)
{
int i, j, t, sum, MAX;
t = n / m;
for (i = j = sum= ; i < m; i++)
{
MAX = -;
for (j = ; j < t; j++)
if (MAX < a[i*t+j]) MAX = a[i*t+j];
sum += MAX;
if (sum > k) return true;
}
return sum > k;
} int main()
{
int k, m, up, down, i, sum;
//freopen("in", "r", stdin);
while (scanf("%d%d", &n, &k), n >= && k >= )
{
for (i = sum = ; i < n; i++)
{
scanf("%d", a + i);
sum += a[i];
}
if (sum <= k) puts("-1");
else {
down = ; up = n;
while (down < up)
{
m = (up + down) / ;
if (Can(m, k)) up = m;
else down = m + ;
}
printf("%d\n", up);
}
}
return ;
}

CSU 1364 Interview RMQ的更多相关文章

  1. CSU 1809 - Parenthesis - [前缀和+维护区间最小值][线段树/RMQ]

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1809 Bobo has a balanced parenthesis sequenc ...

  2. CSU 1553 Good subsequence(RMQ问题 + 二分)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n nu ...

  3. csu 1553(RMQ+尺取法)

    1553: Good subsequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 794  Solved: 287[Submit][Statu ...

  4. *HDU3486 RMQ+二分

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

  5. hdu 3486 Interviewe (RMQ+二分)

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

  6. CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...

  7. CSU1553 Good subsequence —— 二分 + RMQ/线段树

    题目链接: http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1553 Description Give you a sequence of n n ...

  8. 3486 ( Interviewe )RMQ

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

  9. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

随机推荐

  1. direct2d: antialiasing and drawing a line with a 1 pixel stroke

    http://xboxforums.create.msdn.com/forums/t/61448.aspx I'm currently porting a number of custom MFC C ...

  2. Collections库使用

    Date: 2019-05-27 Author: Sun Collections库 ​ Python拥有一些内置的数据类型,比如str, int, list, tuple, dict等, collec ...

  3. 详解:(cron , crontab , anacron)

    导读: 人类把时间做了切割,想象一条笔直的线永远向前,本来这条直线上什么都没有,但是人类根据时间的长短(单位)在这条直线上做了密密麻麻的标记(世纪-年-月-日-时-分-秒-纳秒......),通过这样 ...

  4. Vue style里面使用@import引入外部css, 作用域是全局的解决方案

    问题描述 使用@import引入外部css,作用域却是全局的 <template> </template> <script> export default { na ...

  5. poj1284 && caioj 1159 欧拉函数1:原根

    这道题不知道这个定理很难做出来. 除非暴力找规律. 我原本找的时候出了问题 暴力找出的从13及以上的答案就有问题了 因为13的12次方会溢出 那么该怎么做? 快速幂派上用场. 把前几个素数的答案找出来 ...

  6. docker 下修改 mysql sql_mode和配置文件

    原文:docker 下修改 mysql sql_mode和配置文件 打开PowerShell 首先创建mysql容器,这里我们指定使用mysql5.7的版本 docker run -d -p 3306 ...

  7. HDU 4965 Fast Matrix Calculation 矩阵乘法 乘法结合律

    一种奇葩的写法,纪念一下当时的RE. #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  8. 题解 洛谷 P1580 【yyy loves Easter_Egg I】

    一言不合上代码: #include<cstdio> #include<cstring> ],bz[],dmz[]; int maohao,xf,ls,sss,lll,xxf,x ...

  9. Gitlab command line instructions

    Git global setup git config --global user.name "winner" git config --global user.email &qu ...

  10. FS,FT,DFT,DFS和DTFT的关系

    对于初学数字信号(Digital Signal Processing,DSP)的人来说,这几种变换是最为头疼的,它们是数字信号处理的理论基础,贯穿整个信号的处理. FS:时域上任意连续的周期信号可以分 ...