Interviewe(hdu3486)
Interviewe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6689 Accepted Submission(s): 1582
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

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.
7 100 7 101 100 100 9 100 100 110 110
-1 -1
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.
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<deque>
7 #include<stack>
8 #include<math.h>
9 using namespace std;
10 typedef long long LL;
11 int ans[200005];
12 void RMQ(int n);
13 int mnsum[200005][22];
14 int mm[200005];
15 int rmq(int x, int y);
16 int check(int n,int k,int s);
17 int main(void)
18 {
19 int n;
20 int k;
21 while(scanf("%d %d",&n,&k),n>0&&k>0)
22 {
23 int i;
24 int sum = 0;
25 int minn = -1;
26 for(i = 1; i <= n; i++)
27 {
28 scanf("%d",&ans[i]);
29 sum += ans[i];
30 }
31 if(sum <= k)printf("-1\n");
32 else
33 {
34 RMQ(n);
35 for(i = 1; i <= sqrt(1.0*n); i++)
36 {
37 int x = n/i;
38 int xx = check(n,x,k);
39 if(xx!=-1)
40 {
41 minn = xx;
42 break;
43 }
44 }
45 if(minn == -1)
46 {
47 int y = n/(sqrt(1.0*n))-1;
48 for(i = y; i >= 1; i--)
49 {
50 int xx = check(n,i,k);
51 if(xx!=-1)
52 {
53 minn = xx;
54 break;
55 }
56 }
57 }
58 printf("%d\n",minn);
59 }
60 }
61 return 0;
62 }
63 void RMQ(int n)
64 {
65 mm[0] = -1;
66 for(int i = 1; i<=n; i++)
67 {
68 mm[i] = ((i&(i-1)) == 0) ? mm[i-1]+1:mm[i-1];
69 mnsum[i][0] = ans[i];
70 }
71 for(int j = 1; j<=mm[n]; j++)
72 for(int i = 1; i+(1<<j)-1<=n; i++)
73 mnsum[i][j] = max(mnsum[i][j-1], mnsum[i+(1<<(j-1))][j-1]);
74 }
75 int rmq(int x, int y)
76 {
77 int k = mm[y-x+1];
78 return max(mnsum[x][k], mnsum[y-(1<<k)+1][k]);
79 }
80 int check(int n,int k,int s)
81 { //if(k==1)printf("1\n");
82 int sum = 0;
83 int i;
84 int cnt = 0;
85 for(i = 1; i+k-1<= n; i+=k)
86 {
87 cnt++;
88 sum += rmq(i,i+k-1);
89 if(sum > s)return cnt;//最小原则;
90 }
91 return -1;
92 }
Interviewe(hdu3486)的更多相关文章
- *HDU3486 RMQ+二分
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDOJ 3486 Interviewe
人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊 I ...
- Interviewe
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 3486 Interviewe
题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...
- hdu3486 ST表区间最值+二分
还是挺简单的,但是区间处理的时候要注意一下 #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- Interviewe HDU - 3486( 暴力rmq)
面试n个人,可以分任意组数,每组选一个,得分总和严格大于k,问最少分几组 就是暴力嘛...想到就去写吧.. #include <iostream> #include <cstdio& ...
- HDU 3486 Interviewe RMQ
题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...
- hdu 3484 Interviewe RMQ+二分
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; + ...
随机推荐
- 汇编LED实验
汇编语言点亮LED 拿到一款全新的芯片,第一个要做的事情的就是驱动其 GPIO,控制其 GPIO 输出高低电平. GPIO口是IO口的一个功能之一. 一.接下来的步骤离不开芯片手册: 1.使能所有时钟 ...
- Shell 格式化输出printf、awk
目录 Shell 文件的格式化与相关处理 printf.awk 格式化打印printf 案例.格式化输出文件内容 输出命令echo 案例 awk数据处理工具 语法格式 处理流程 AWK内置变量 条件 ...
- Java、Scala获取Class实例
Java获取Class实例的四种方式 package com.test; /** * @description: TODO * @author: HaoWu * @create: 2020/7/22 ...
- JavaScript设计模式,单例模式!
单例设计模式:保证一个类仅有一个实例,并且提供一个访问它的全局访问点.有些对象只需要一个,这时可用单例模式. 传统的单例模式 和new 创建对象的调用不一样 调用者要调用xxx.getInstance ...
- pyqt5 的串口编写进度
2020.12.18 今天遇到一个问题, 想用回车实现串口数据的发送. 下面这句话是让光标移动到文字的尾部,但是不能够实现. 对QTextEdit控件中的文字改写,或清除后,再调用下面的移动到尾部,就 ...
- c++string转const char*与char*
#include <iostream> #include <string> #include <memory> using namespace std; const ...
- Linux学习 - 脚本安装包
脚本安装包不是独立的软件包类型,常见安装的是源码包
- 【Java】面向类与对象
一.面向对象 对象封装:私有变量+公共方法 方法与构造方法 this变量 Animal.java public class Animal { String name; int age; void mo ...
- 12月第二周bug总结
1.bug总结 复制 别人的依赖和依赖指定类型 报错 解决:依赖还没加载完成,你就指定了版本型号,所以报错,所以先让他加载依赖,后指定该型号 eureka(优瑞卡) 注册服务 控制台没有显示出来的话 ...
- java多线程5:线程间的通信
在多线程系统中,彼此之间的通信协作非常重要,下面来聊聊线程间通信的几种方式. wait/notify 想像一个场景,A.B两个线程操作一个共享List对象,A对List进行add操作,B线程等待Lis ...