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 , 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.
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; + ...
随机推荐
- EXCEL-批量删除筛选出的行,并且保留首行
筛选->ctrl+G->可见单元格->鼠标右键->删除整行. 之前的时候,是有个方法类似于上述步骤,可以保留标题行的,但是,不知道是不是少了哪一步,上述过程总是会删除标题行.就 ...
- Identity Server 4 从入门到落地(三)—— 创建Web客户端
书接上回,我们已经搭建好了基于Identity Server 4的认证服务和管理应用(如果还没有搭建,参看本系列前两部分,相关代码可以从github下载:https://github.com/zhen ...
- 一个神奇的JS混淆,JSFuck!
JSFuck,整体由6个字符[, ], (, ), !, +组成,但却是可以正常运行的JS代码,JSFuck程序可以在任何Web浏览器或引擎中运行解释JavaScript! 看一段代码,源代码为:do ...
- Spark产生数据倾斜的原因以及解决办法
Spark数据倾斜 产生原因 首先RDD的逻辑其实时表示一个对象集合.在物理执行期间,RDD会被分为一系列的分区,每个分区都是整个数据集的子集.当spark调度并运行任务的时候,Spark会为每一个分 ...
- Flask + Nginx + uwsgi 部署过程
一.安装Flask 1.itsdangerous tar xvf itsdangerous-0.23.tar.gz cd itsdangerous-0.23/ python setup.py inst ...
- js 时间戳转换为年月日时分秒的格式
<script type="text/javascript"> var strDate = ''; $(function(){ // 获取时间戳 var nowDate ...
- 【力扣】82. 删除排序链表中的重复元素 II
存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 没有重复出现 的数字. 返回同样按升序排列的结果链表. 示例 1: 输入:hea ...
- 🔥🔥🔥Flutter 字节跳动穿山甲广告插件发布 - FlutterAds
前言 Flutter 已成为目前最流行的跨平台框架之一,在近期的几个大版本的发布中都提到了 Flutter 版本 Google 广告插件 [google_mobile_ads] .对于"出海 ...
- 转:Java多线程基础问题
如果你即将去一家从事大型系统研发的公司进行Java面试,不可避免的会有多线程相关的问题.下面是一些针对初学者或者新手的问题,如果你已经具备良好的基础,那么你可以跳过本文,直接尝试针对进阶水平的Java ...
- 转:Intent 操作常用URI代码示例
以下是常用到的Intent的URI及其示例,包含了大部分应用中用到的共用Intent 一.打开一个网页,类别是Intent.ACTION_VIEW 1 2 Uri uri = Uri.parse(&q ...