Gym 100917J---dir -C(RMQ--ST)
题目链接
http://codeforces.com/gym/100917/problem/D
problem description
Famous Berland coder and IT manager Linus Gates announced his next proprietary open-source system "Winux 10.04 LTS"
In this system command "dir -C" prints list of all files in the current catalog in multicolumn mode.
Lets define the multicolumn mode for number of lines l. Assume that filenames are already sorted lexicographically.
- We split list of filenames into several continuous blocks such as all blocks except for maybe last one consist of l filenames, and last block consists of no more than l filenames, then blocks are printed as columns.
- Width of each column wi is defined as maximal length of the filename in appropriate block.
- Columns are separated by 1 × l column of spaces.
- So, width of the output is calculated as
, i.e. sum of widths of each column plus number of columns minus one.
Example of multi-column output:
a accd e t
aba b f wtrt
abacaba db k
In the example above width of output is equal to 19.
"dir -C" command selects minimal l, such that width of the output does not exceed width of screen w.
Given information about filename lengths and width of screen, calculate number of lines l printed by "dir -C" command.
First line of the input contains two integers n and w — number of files in the list and width of screen (1 ≤ n ≤ 105, 1 ≤ w ≤ 109).
Second line contains n integers fi — lengths of filenames. i-th of those integers represents length of i-th filename in the lexicographically ordered list (1 ≤ fi ≤ w).
Print one integer — number of lines l, printed by "dir -C" command.
11 20
1 3 7 4 1 2 1 1 1 1 4
3 题意:有n个目录名字符串,长度为a[1]~a[n] 屏幕宽为w ,现在要按照已经给的目录循序一列一列的放,每一列放x个,最后一列放<=x个 要求每一列目录名左端对整齐 ,形成一个长方形的块 ,且块与块之间空一格,且不能超过屏幕的宽度,求最小的行数; 思路:先对输入长度处理,用ST算出每个区间的最大值,然后枚举行数x 从1 ~ n; 代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+;
int a[MAXN],m[][MAXN];
int n;
LL w; int main()
{
while(scanf("%d%I64d",&n,&w)!=EOF)
{
memset(m,,sizeof(m));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
m[][i]=a[i];
}
for(int i=;i<=(int)log(n)/log();i++)
{
for(int j=;j+(<<i)-<=n;j++)
m[i][j]=max(m[i-][j],m[i-][j+(<<(i-))]);
} for(int i=;i<=n;i++)
{
int k=(int)log(i);
long long sum=;
for(int j=;j<n/i;j++)
{
sum+=(long long)max(m[k][j*i+],m[k][i*(j+)-(<<k)+])+;
}
if(n%i!=) {
k=(int)log(n%i);
sum+=(long long)max(m[k][n-n%i+],m[k][n-(<<k)+])+;
}
if(sum-<=w){
printf("%d\n",i);
break;
}
}
}
return ;
}
Gym 100917J---dir -C(RMQ--ST)的更多相关文章
- poj3368(RMQ——ST)
Frequent values Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16543 Accepted: 5985 ...
- [NOI2010]超级钢琴(RMQ+堆)
小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i个音符的美妙度为Ai,其中Ai可正可负 ...
- codeforces gym #102082C Emergency Evacuation(贪心Orz)
题目链接: https://codeforces.com/gym/102082 题意: 在一个客车里面有$r$排座位,每排座位有$2s$个座位,中间一条走廊 有$p$个人在车内,求出所有人走出客车的最 ...
- HDU 5726 GCD(RMQ+二分)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5726 题意:给出一串数字,现在有多次询问,每次询问输出(l,r)范围内所有数的gcd值,并且输出有多 ...
- BZOJ 1067:[SCOI2007]降雨量(RMQ+思维)
http://www.lydsy.com/JudgeOnline/problem.php?id=1067 题意:…… 思路:首先我们开一个数组记录年份,一个记录降雨量,因为年份是按升序排列的,所以我们 ...
- POJ 3419 Difference Is Beautiful(RMQ变形)
题意:N个数,M个询问,每个询问为一个区间,求区间最长连续子序列,要求每个数都不同(perfect sequence,简称PS). 题解:很容易求出以每个数为结尾的ps,也就是求区间的最大值.有一个不 ...
- 2015 多校联赛 ——HDU5289(二分+ST)
Assignment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- (RMQ版)LCA注意要点
inline int lca(int x,int y){ if(x>y) swap(x,y); ]][x]]<h[rmq[log[y-x+]][y-near[y-x+]+]])? rmq[ ...
- 【BZOJ 2006】2006: [NOI2010]超级钢琴(RMQ+优先队列)
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2792 Solved: 1388 Description 小 ...
- UVA - 1618 Weak Key(RMQ算法)
题目: 给出k个互不相同的证书组成的序列Ni,判断是否存在4个证书Np.Nq.Nr.Ns(1≤p<q<r<s≤k)使得Nq>Ns>Np>Nr或者Nq<Ns&l ...
随机推荐
- 将不确定变为确定~transactionscope何时提升为分布式事务?(sql2005数据库解决提升到MSDTC的办法)
回到目录 对于transactionscope不了解的同学,可以看我的相关文章 第二十六回 将不确定变为确定~transactionscope何时提升为分布式事务? 第二十七回 将不确定变为确 ...
- Apache Commons CLI命令行启动
今天又看了下Hangout的源码,一般来说一个开源项目有好几种启动方式--比如可以从命令行启动,也可以从web端启动.今天就看看如何设计命令行启动... Apache Commons CLI Apac ...
- Atitit 语音识别的技术原理
Atitit 语音识别的技术原理 1.1. 语音识别技术,也被称为自动语音识别Automatic Speech Recognition,(ASR),2 1.2. 模型目前,主流的大词汇量语音识别系统多 ...
- java初学者应掌握的30个基本概念
核心提示:OOP中唯一关系的是对象的接口是什么,就像计算机的销售商她不管电源内部结构 是怎样的,他只关系能否给你提供电就行了,也就是只要知道can or not而不是how and why. 基本概念 ...
- C++生成二级制文件过程(预处理->编译->链接 )
转载请注明出处 Windows下C++编程,通过VC生成工程,编写C++源文件,点运行,代码没问题直接出结果.VC什么都帮我们搞了,不了解其中过程也完全没问题. 转到linux下写c++,总觉得有点虚 ...
- Vue+Webpack+Grunt集成
说明 Vue.Grunt.Webpack的知识请看官方网站 Grunt Tasks:构建.开发调试.打包,命令:grunt build,grunt default,grunt zipall... We ...
- 怎样将多个CSS文件导入一个CSS文件中
问题: 在HTML中引入css的其中的两个方法: 导入式和链接式的目的都是将一个独立的css文件引入一个文件中,二者的区别不大,事实上,二者最大的区别在于链接式使用html的标记引入外部css文 ...
- windows phone listbox的点击事件
前台 <ListBox x:Name="> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin=& ...
- 基于TFS实践敏捷-可视化管理
TFS是基于微软平台一套不错的系统,支持源码管理+运行调试+持续集成+自动化测试+Bug管理+代码评审+任务项管理+文档管理+沟通管理.基于TFS 2015实践看板管理,让团队的数据可视化,让大家更多 ...
- Testing - 测试基础 - 模型
珠玉在前,不再赘言. 软件测试模型 软件测试模型汇总