题目链接: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. P3958奶酪

    这个题是2017noip提高组的真题,是一个深度搜索题,得分轨迹:10-80-100pts. 在三维空间里,存在可能连通的洞(半径r),问是否可以通过这些洞从底部到达顶部.一开始我联想到了01迷宫,以 ...

  2. 数位DP 计划

    通常的数位dp可以写成如下形式: [cpp] view plain copy int dfs(int i, int s, bool e) { if (i==-1) return s==target_s ...

  3. Python 如何用列表实现栈和队列?

    1.栈结构,其实就是一个后进先出的一个线性表,只能在栈顶压入或弹出元素.用列表表示栈,则向栈中压入元素,可以用列表的append()方法来实现,弹出栈顶元素可以用列表的pop()方法实现. >& ...

  4. Neo4j源代码分析

    1.下载neo4j源码 https://github.com/neo4j/neo4j/ 参考文章 原文地址:https://blog.csdn.net/e15273/article/details/7 ...

  5. Java——绘制五角星

    Java2D支持通过GeneralPath实现绘制任意的几何形状. 步骤:1)实例化GeneralPath对象 2)调用moveTo()方法锚地开始点坐标 3)调用lineTo()或curveTo() ...

  6. 【源码解读】cycleGAN(二) :训练

    源码地址:https://github.com/aitorzip/PyTorch-CycleGAN 训练的代码见于train.py,首先定义好网络,两个生成器A2B, B2A和两个判别器A, B,以及 ...

  7. 计算视图相对坐标时convertPoint:toView: ,UIApplication sharedApplication - keyWindow is nil?

    UIWindow *window = [UIApplication sharedApplication].keyWindow; window 为nil的原因:在指定rootViewController ...

  8. git上传代码到code.csdn.net

    国内有code.csdn.net速度很快 用git上传需要去下载git程序 很简单. 我是Windows下 先code.csdn.net创建一个项目 https://code.csdn.net/das ...

  9. python小实例

    一.跳动的心 love = '\n'.join([''.join([('love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0 ...

  10. 原生JS滚动条位置处理

    // 滚动条位置 var scrollPosition = { // 位置 result: 0, // 监听位置 rememberPosition: function () { var type = ...