Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao 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?
Input
The input consists of multiple cases.
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.
Output
For each test case, print only one number indicating the smallest m you can find. If you can’t find any, output -1 instead.
Sample Input
11 300
7 100 7 101 100 100 9 100 100 110 110
-1 -1
Sample Output
3
Hint
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.
题意:
给你n个人的能力值,和一个数值k,让你求一个最小的m,使其把n个人分成 floor(n/m) 个块,每一个块中最大值加起来的sum和严格的大于k 。
思路:
本认为是一个rmq+二分的题目,但是因为如果分块的最后还剩下人,那些人将被直接忽略,导致并没有二分的单调性质。
也可以看下这组数据:
8 282
69 27 64 87 37 40 21 28
答案应该是 5
二分对这组数据是无能为力的。
那么我们根据k值数组中的最大值来判断最小需要多少个面试官来枚举,,,又因为数据太弱,所以可以直接过。
我们用ST表来预处理数组后,O(1) 询问区间最值。
细节见代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2) { ans = ans * a % MOD; } a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int *p);
const int maxn = 200010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];//原始输入数组
int st[maxn][25];//st表
void init(int n)
{
for (int i = 0; i < n; i++)
st[i][0] = a[i];
for (int i = 1; (1 << i) <= n; i++)
{
for (int j = 0; j + (1 << i) - 1 < n; j++)
st[j][i] = max(st[j][i - 1],st[j + (1 << (i - 1))][i - 1]);
}
}
int query(int l, int r)
{
int k = (int)(log((double)(r - l + 1)) / log(2.0));
return max(st[l][k],st[r - (1 << k) + 1][k]);
}
int n;
ll k;
ll check(int mid)
{
int num=n/mid;
ll res=0ll;
int l,r;
l=0;
r=num-1;
repd(i,1,mid)
{
res+=1ll*query(l,r);
l+=num;
r+=num;
}
return res;
}
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
gbtb;
while(cin>>n>>k)
{
if(n<0)
{
break;
}
// ll
rep(i,0,n)
{
cin>>a[i];
}
init(n);
int l=1;
int r=n;
int mid;
int ans=-1;
int x=max(1ll,k/max(1,query(0,n-1)));
repd(i,x,n)
{
if(check(i)>k)
{
ans=i;
break;
}
}
cout<<ans<<endl;
}
return 0;
}
inline void getInt(int *p)
{
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
} else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}
Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)的更多相关文章
- BZOJ 4556 [Tjoi2016&Heoi2016]字符串 ——后缀数组 ST表 主席树 二分答案
Solution 1: 后缀数组暴力大法好 #include <map> #include <cmath> #include <queue> #include &l ...
- Oracle非归档模式下脱机数据文件
正常情况下,要想对数据文件脱机,必须在归档模式下,这是ORACLE自动保护的一种措施,防止在非归档模式下对数据文件脱机,造成数据丢失.如果想在非归档模式下执行数据文件脱机操作,则需要加上“for dr ...
- (转)如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐)
如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐) 2013-09-10 16:01 2152人阅读 ...
- wordpress非管理员看不到数据需有manage_options权限
今天ytkah在调试一个新功能的时候发现wordpress非管理员看不到一些插件的数据,比如editor,添加一些用户权限还是不行,不得已直接把administrator所有的权限都添加测试一遍,最后 ...
- Interviewe HDU - 3486( 暴力rmq)
面试n个人,可以分任意组数,每组选一个,得分总和严格大于k,问最少分几组 就是暴力嘛...想到就去写吧.. #include <iostream> #include <cstdio& ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- 洛谷 P2251 质量检测(st表)
P2251 质量检测 题目提供者ws_ly 标签 难度 普及/提高- 题目描述 为了检测生产流水线上总共N件产品的质量,我们首先给每一件产品打一个分数A表示其品质,然后统计前M件产品中质量最差的产品的 ...
- RMQ算法使用ST表实现
RMQ RMQ (Range Minimum Query),指求区间最小值.普通的求区间最小值的方法是暴力. 对于一个数列: \[ A_1,~ A_2,~ A_3,~ \cdots,~ A_n \] ...
- 2019CCPC网络赛 C - K-th occurrence HDU - 6704(后缀数组+ST表+二分+主席树)
题意 求区间l,r的子串在原串中第k次出现的位置. 链接:https://vjudge.net/contest/322094#problem/C 思路 比赛的时候用后缀自动机写的,TLE到比赛结束. ...
随机推荐
- linux挂载问题
说明 Linux系统在使用光盘.软盘或U盘时,必须先执行挂载(mount)命令. 挂载命令会将这些存储介质指定成系统中的某个目录,以后直接访问相应目录即可读写存储介质上的数据. 挂载光盘 mount ...
- DeepWalk 安装指南
DeepWalk 安装指南 创建 conda 虚拟环境 conda create -n deepwalk pip python=3.5 conda activate deepwalk 安装 deepw ...
- leetcode 297二叉树的序列化与反序列化
to_string(x) 将数字x转化为string atoi(x) 将char转化为int stoi(x) 将string 转化为int 采用中序遍历的顺序存储,NULL用#表示,以,分隔,O(n) ...
- [mysql]SQL语句-新增/修改 创建时间 更新时间
SQL关键词 要注意大小写 已建表,之前没有创建时间列, 现新增1列创建时间,并设置默认值为当前时间 --添加CreateTime 设置默认时间 CURRENT_TIMESTAMP ALTER T ...
- easyui tree checkbox 单选控制
参考文档:中文网:http://www.jeasyui.net/plugins/185.html easyui-tree的checkbox默认是多选的, 如何控制只能单选一个子节点,看代码: $('# ...
- 2018-12-10 发布 vue全家桶实现的商城web-app,真实数据接口开发
项目地址:https://github.com/Rosen97/web-shop.git 博客地址:https://segmentfault.com/a/1190000017323841
- java 换包
1.进入目录:cd /opt/cw_isc/ 2.查看:ls 3.查看进程:ps -ef|grep aw-sc-package-all.jar 4.杀死进程kill -9 3982 5.查看进程:ps ...
- [JS] 点击按钮触发后台事件前,弹出确认框
只需要在button中设置onclick属性触发事件即可 下面以ASP.NET代码为例, ASP.NET中按钮客户端触发js代码的属性是OnClientClick <asp:Button ID= ...
- neo4j3.0多数库切换
动机 类似与关系型数据库,创建了多个数据库 想要像访问关系型数据库那样来可以无缝切换多个数据库 然而,在neo4j 3.0都暂时没有办法做到:每次启动neo4j,它只能读取一个数据库.比如,现在有两个 ...
- Android Studio 如何获取 text文本内容
1.找到目录的main先建立assets格式的文件夹 2.再把需要读取的txt 文件放入到该文件夹下(名字随意),这里取 list.txt. 文件内容 格式如下 3.读取文本内容 工具代码 /** * ...