UVALive 7325 Book Borders
-------------------------------------------------------------------------------------------------------------
我们可以预处理除长度为L的区间能存下的从第一个单词开始的单词的次数
然后枚举区间长度从a到b 每次从一个区间最后一个单词结尾跳到另一个区间最后一个单词结尾
这样相邻两次跳跃的总长度至少为一个区间长度
设单词总长为$len$ 对于长度为$x$的区间 总的跳跃次数不超 $len\ /\ x * 2$
因此整个问题的复杂度根据调和级数分析发现是 $O(lenlog{len})$
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = ;
int a[N], pre[N], sum[N];
char s[N];
int len, n;
int main()
{
while(gets(s) != NULL)
{
n = ;
len = strlen(s) + ;
for(int i = ; i < len; ++i)
{
if(s[i] < 'a' || s[i] > 'z')
{
++n;
a[n] = i + - sum[n - ];
sum[n] = sum[n - ] + a[n];
}
pre[i + ] = n;
}
int L, R, ans, now;
scanf("%d%d", &L, &R);
getchar();
++L;
++R;
for(int i = L; i <= R; ++i)
{
ans = -;
now = ;
while(now != len)
{
ans += a[pre[now] + ];
now = sum[pre[min(now + i, len)]];
}
printf("%d\n", ans);
}
}
return ;
}
UVALive 7325 Book Borders的更多相关文章
- UVALive 7325 Book Borders (模拟)
Book Borders 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/B Description A book is bein ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- CSS 笔记一(Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width)
Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width CSS Introduction: CSS stands for ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- mysql 修改表字段默认值
alter table 表名 alter column 字段名 drop default; (若本身存在默认值,则先删除) alter table 表名 alter column 字段名 set de ...
- Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式
Python生成文本格式的excel\xlwt生成文本格式的excel\Python设置excel单元格格式为文本\Python excel xlwt 文本格式 解决: xlwt 中设置单元格样式主要 ...
- P2586 [ZJOI2008]杀蚂蚁
传送门 快乐模拟,修身养性 代码长度其实还好,主要是细节多 只要知道一些计算几何基础知识即可快乐模拟,按着题目要求一步步实现就行啦 注意仔细读题,蚂蚁每 $5$ 秒乱走一次的时候是只要能走就走了,不一 ...
- IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); 时,报COMException
解决办法: 在Program.cs的Main函数中添加如下代码: ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
- 行内元素(例如)设置float之后才能用width调整宽度
因为只有块元素才会有物理属性,在css世界里边,有三种形态的东西, 1. 块元素. 特性:有物理属性,width,height写值起作用,而且要占据一行.2. 内联元素. 特性:没有物理属性.但是ma ...
- SPA(单页面应用)和MPA(多页面应用)
话不多说,直接看图,一目了然
- 2019-11-22-Roslyn-在多开发框架让-msbuild-的-Target-仅运行一次
title author date CreateTime categories Roslyn 在多开发框架让 msbuild 的 Target 仅运行一次 lindexi 2019-11-22 09: ...
- CCPC-Wannafly Winter Camp Day1 爬爬爬山 (最短路)
题目描述 爬山是wlswls最喜欢的活动之一. 在一个神奇的世界里,一共有nn座山,mm条路. wlswls初始有kk点体力,在爬山的过程中,他所处的海拔每上升1m1m,体力会减11点,海拔每下降1m ...
- YUM源使用阿里镜像
备份系统自带的yum源 # 前提:需要联网才能使用 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bac ...
- layui token 过期 重新登陆
这个方法你要全局设置 //jquery全局配置 $.ajaxSetup({ cache: false, crossDomain: true, headers :{' ...