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 ...
随机推荐
- HNUSTOJ-1051 最长的波动序列
1051: 最长的波动序列 时间限制: 1 Sec 内存限制: 128 MB提交: 47 解决: 13[提交][状态][讨论版] 题目描述 有一个长度为N的整数序列,序列里面的数是两两不同的,现在 ...
- CSP2019
$CSP\space S$ 格雷码 $solution:$ 直接模拟即可. 时间复杂度 $O(n)$ . #include<iostream> #include<cstring> ...
- mysql proxysql的简单部署读写分离
环境需求(centos) proxysql-server(1)-- 地址:proxysql-service mysql-master-server(1)--- 地址:mysql1-service my ...
- npm学习(一)之安装、更新以及管理npm版本
安装npm 安装前须知: npm是在Node中编写的,因此需要安装Node.js才能使用npm.可以通过Node.js网站安装npm,或者安装节点版本管理器NVM. 如果只是想开始探索npm,使用No ...
- jQuery进阶第三天(2019 10.12)
一.原生JS快捷的尺寸(属性)(注意这些属性的结果 不带PX单位) clientWidth/clientHeight =====> 获得元素content+padding的宽/高: offse ...
- Trait讲解
<?php /** * Trait解决PHP单继承的一种方法,使开发人员在不同层次结构的类中复用属性和方法 * Trait无法实例化 * Trait不是类,不能被继承,所以不能再Trait中不能 ...
- WPF游戏,使用move游戏开发
我看了好多游戏的源码,其实每一个,我想做,rpg的都需要移动,那么wpf,win8应用,数据绑定,我们需要一个Thread来让人物移动. 于是用move. 在每个人物,自己和敌人,npc类,都有一个m ...
- Spring MVC 使用MultipartResolver与Commons FileUpload传输文件
配置MultipartResolver:用于处理表单中的file <!-- 配置MultipartResolver 用于文件上传 使用spring的CommosMultipartResolver ...
- java 中的编码(二)
UTF-16编码规则: 按照UTF-16编码规则计算下Unicode码位为 U+10002 (十进制:65538)的字符的UTF-16编码表示. U+10002落在 [U+10000, U+10FFF ...
- @Component和@Bean以及@Autowired、@Resource
1. 有这么一个故事,从xml配置文件的bean说起 Spring用xml配置文件的时候(不知道阅读这篇文章的你用没用过,我用过一段时间,那是黑暗伤痛的回忆QQQ),一个xml配置文件里面有很多个 ...