https://www.bnuoj.com/v3/problem_show.php?pid=52781

【AC】

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=5e5+;
char str[maxn];
int l;
int a[maxn];
int b[maxn];
int n,m;
void init()
{
memset(a,-,sizeof(a));
memset(b,-,sizeof(b));
int len=;
for(int i=;i<l;i++)
{
if(str[i]==' ')
{
b[i-]=i-len;
a[i-]=len;
len=;
}
else
{
len++;
}
}
if(len)
{
b[l-]=l-len;
a[l-]=len;
}
for(int i=l-;i>=;i--)
{
if(b[i]==-)
{
b[i]=b[i+];
}
}
for(int i=l-;i>=;i--)
{
if(a[i]==-)
{
a[i]=a[i+];
}
}
} int solve(int x)
{
int ans=;
int cur=;
while(cur<l)
{
ans+=a[cur]+;
if(cur+x>=l) break;
cur=b[cur+x];
}
return ans-;
}
int main()
{
gets(str);
l=strlen(str);
scanf("%d%d",&n,&m);
init();
for(int i=n;i<=m;i++)
{
int ans=solve(i);
printf("%d\n",ans);
}
return ;
}

【字符串】BNUOJ 52781 Book Borders的更多相关文章

  1. bnuoj 29375 Two Strings(字符串?)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29375 [题意]:可以对两字符串进行如下操作: 1.可以无损耗交换相邻两个字符(可以理解成交换任意字 ...

  2. bnuoj 33647 Angry Grammar Nazi(字符串)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33647 [题意]:字符串匹配,暴力配就行了 [题解]:截出单词,然后进行匹配就行了 [code]: ...

  3. BNUOJ 1006 Primary Arithmetic

    Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...

  4. bnuoj 34985 Elegant String DP+矩阵快速幂

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 We define a kind of strings as elegant s ...

  5. UVALive 7325 Book Borders (模拟)

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

  6. bnuoj 20832 Calculating Yuan Fen(暴力模拟)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...

  7. bnuoj 20834 Excessive Space Remover(水水)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=20834 [题意]: 每次减少一半的空格,问经过多少次操作能得到每个单词之间的空格为1,输入字符串大小 ...

  8. BNUOJ 26475 Cookie Selection

    LINK:BNUOJ 26475 Cookie Selection 题意: 你在不停的输入数字a1,a2,a3,......,ak,当你输入#时,就把已输入数字中的第k/2+1删除,然后剩下的数字又组 ...

  9. 【字符串+BFS】Problem 7. James Bond

    https://www.bnuoj.com/v3/external/gym/101241.pdf [题意] 给定n个字符串,大小写敏感 定义一个操作:选择任意m个串首尾相连组成一个新串 问是否存在一个 ...

随机推荐

  1. @AutoWired注解使用时可能会发生的错误

    @Autowired注解:用于对Bean的属性变量.属性的set方法及构造函数进行标注,配合对应的注解处理器完成Bean的自动配置工作.@Autowired注解默认按照Bean类型进行装配.  1.在 ...

  2. npm install -g cnpm --registry=https://registry.npm.taobao.org

    npm install -g cnpm --registry=https://registry.npm.taobao.org

  3. ABAP,Java, nodejs和go语言的web server编程

    ABAP and Java see my blog. nodejs 用nodejs现成的express module,几行代码就能写个server出来: var express = require(' ...

  4. LinuxShell(脚本如何编译问题)

    想学shell的同学请记住: 如果你写好脚本后不给脚本执行权限那也是不行的: 添加执行权限: chmod +x 脚本名.sh 在Linux shell中有一个脚本编译命令: bash -v 脚本名.s ...

  5. htmlunit爬取js异步加载后的页面

    直接上代码: 一. index.html 调用后台请求获取content中的内容. <html> <head> <script type="text/javas ...

  6. codeforces Gym 100338C Important Roads (重建最短路图)

    正反两次最短路用于判断边是不是最短路上的边,把最短路径上的边取出来建图.然后求割边.注意重边,和卡spfa. 正权,好好的dijkstra不用,用什么spfa? #include<bits/st ...

  7. poj1338 Ugly Numbers 打表, 递推

    题意:一个数的质因子能是2, 3, 5, 那么这个数是丑数. 思路: 打表或者递推. 打表: 若该数为丑数,那么一定能被2 或者3, 或者5 整除, 除完之后则为1. #include <ios ...

  8. 使用Google Colab训练神经网络(二)

    Colaboratory 是一个 Google 研究项目,旨在帮助传播机器学习培训和研究成果.它是一个 Jupyter 笔记本环境,不需要进行任何设置就可以使用,并且完全在云端运行.Colaborat ...

  9. 数据库_5_MySQL数据库介绍

    一.MySQL数据库 MySQL:MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB ...

  10. Difference between x:Reference and x:Name

    {x:Reference ...} -> returns just a reference of an object it doesn't create that "bridge&qu ...