【字符串】BNUOJ 52781 Book Borders
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的更多相关文章
- bnuoj 29375 Two Strings(字符串?)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29375 [题意]:可以对两字符串进行如下操作: 1.可以无损耗交换相邻两个字符(可以理解成交换任意字 ...
- bnuoj 33647 Angry Grammar Nazi(字符串)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=33647 [题意]:字符串匹配,暴力配就行了 [题解]:截出单词,然后进行匹配就行了 [code]: ...
- BNUOJ 1006 Primary Arithmetic
Primary Arithmetic 来源:BNUOJ 1006http://www.bnuoj.com/v3/problem_show.php?pid=1006 当你在小学学习算数的时候,老师会教你 ...
- 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 ...
- UVALive 7325 Book Borders (模拟)
Book Borders 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/B Description A book is bein ...
- bnuoj 20832 Calculating Yuan Fen(暴力模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
- bnuoj 20834 Excessive Space Remover(水水)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20834 [题意]: 每次减少一半的空格,问经过多少次操作能得到每个单词之间的空格为1,输入字符串大小 ...
- BNUOJ 26475 Cookie Selection
LINK:BNUOJ 26475 Cookie Selection 题意: 你在不停的输入数字a1,a2,a3,......,ak,当你输入#时,就把已输入数字中的第k/2+1删除,然后剩下的数字又组 ...
- 【字符串+BFS】Problem 7. James Bond
https://www.bnuoj.com/v3/external/gym/101241.pdf [题意] 给定n个字符串,大小写敏感 定义一个操作:选择任意m个串首尾相连组成一个新串 问是否存在一个 ...
随机推荐
- MySQL备份还原介绍
window系统下 1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql ...
- LR常用函数汇总
lr_start_transaction为性能分析标记事务的开始 lr_end_transaction为性能分析标记事务的结束 lr_rendezvous在 Vuser 脚本中设置集合点 lr_thi ...
- restful十项规范
1.协议 API与用户的通信都是通过HTTPS协议进行的 2.域名 应尽量将API部署在专有域名下:https://api.example.com 如果确定API很简单,不会有什么扩展,则可以放在主域 ...
- Python实现1-9数组形成的结果为100的所有运算式
问题: 编写一个在1,2,…,9(顺序不能变)数字之间插入+或-或什么都不插入,使得计算结果总是100的程序,并输出所有的可能性.例如:1 + 2 + 34–5 + 67–8 + 9 = 100. f ...
- atom 自定义快捷键
'atom-text-editor': 'shift-alt-i':'core:move-up' 'shift-alt-space':'core:move-down' 'shift-alt-l':'c ...
- tcpdump简单使用
1.使用wincap将文件放入系统任意路径, 2.进入系统,赋文件可执行权限, 3.输入命令:./tcpdump -i eth0 -s 0 -w xxx.pcap 4.进行数据交互 5.退出程序运行, ...
- 测试框架 Mocha 实例教程(转载:来自阮一峰的一篇文章)
Mocha(发音"摩卡")诞生于2011年,是现在最流行的JavaScript测试框架之一,在浏览器和Node环境都可以使用. 所谓"测试框架",就是运行测试的 ...
- Codeforces Round #275(Div. 2)-C. Diverse Permutation
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...
- 6.python
最早的'密码本' ascii 涵盖了英文字母大小写,特殊字符,数字.01010101ascii 只能表示256种可能,太少,创办了万国码 unicode 16表示一个字符不行,32位表示一个字符. A ...
- js正则函数match、exec、test、search、replace、split使用集合
match 方法 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) 参数 stringObj 必选项.对其进行查找的 String 对 ...