题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5347

-------------------------------------------------------------------------------------------------------------

我们可以预处理除长度为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的更多相关文章

  1. UVALive 7325 Book Borders (模拟)

    Book Borders 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/B Description A book is bein ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. CSS 笔记一(Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width)

    Selectors/ Backgrounds/ Borders/ Margins/ Padding/ Height and Width CSS Introduction: CSS stands for ...

  6. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  7. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. 【暑假培训1】test1

    T1: 30pts:直接暴力三层循环枚举 就就就先不写代码了qwq: 70pts: 因为X+Y+Z==0 所以我们可以考虑枚举X和Y,然后利用↑式子求出Z=-X-Y: 然后touli xcg的70pt ...

  2. HNUSTOJ-1521 塔防游戏

    1521: 塔防游戏 时间限制: 1 Sec  内存限制: 128 MB提交: 117  解决: 38[提交][状态][讨论版] 题目描述 小明最近迷上了塔防游戏,塔防游戏的规则就是在地图上建炮塔,用 ...

  3. PAT Advanced 1042 Shuffling Machine (20 分)(知识点:利用sstream进行转换int和string)

    Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...

  4. PHP 图片合成、仿微信群头像

    PHP 图片合成.仿微信群头像 参考文章: 作者:凯歌~,php图片合成方法(多张图片合成一张). 经过测试,略作调整和注释,感谢分享. 欢迎提出改善优化意见! 示例代码: /** * 合成图片 * ...

  5. python json、pickle

    文章部分转自:https://www.cnblogs.com/lincappu/p/8296078.html json:用于字符串和Python数据类型间进行转换pickle: 用于python特有的 ...

  6. Deepin(Ubuntu)安装rpm软件包

    1.首先安装alien和fakeroot这两个软件,alien可以将rpm转换为deb包. 在终端中输入命令 sudo apt-get install alien fakeroot 2.使用alien ...

  7. Django【第3篇】:Django之模板语法

    Django框架之第三篇模板语法(重要!!!) 一.什么是模板? 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法分类 一.模板语法之变量:语法为 {{ }}: ...

  8. SSM常用配置文件头模板

    web.xml文件头 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&q ...

  9. OCP内容

    安装 --网络 --存储 --用户 --对象 --ASM (包含前面的内容的复习)--内存管理 -- 备份 --闪回 -- 事务 --sql 编程

  10. php----等比缩放图片

    <?php /** * Created by PhpStorm. * User: admin * Date: 2019/11/19 * Time: 8:54 */ $filename = 'lo ...