CF526D Om Nom and Necklace
我们可以把AB看成S,则要找的串可以写成SSSSA或者SSSSS。假设S出现了Q次,那么A出现了Q % k次,则B出现了 Q / k - Q % k次.
当ABABA是SSS的形式时,B可以为空字符,判断Q / k - Q % k>=0。
当ABABA是SSA的形式时,判断Q / k - Q % k > 0。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 1e6 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), las = ' ';
while(!isdigit(ch)) las = ch, ch = getchar();
while(isdigit(ch)) ans = ans * + ch - '', ch = getchar();
if(las == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar(x % + '');
} int n, k;
char s[maxn];
int f[maxn]; void init()
{
for(int i = , j = ; i <= n; ++i)
{
while(j && s[j + ] != s[i]) j = f[j];
if(s[j + ] == s[i]) j++;
f[i] = j;
}
} bool work(int i, int cir)
{
int x = i / cir;
if(i % cir) return x / k > x % k;
else return x / k >= x % k;
} int main()
{
n = read(), k = read();
scanf("%s", s + );
init();
for(int i = ; i <= n; ++i) write(work(i, i - f[i]));
enter;
return ;
}
CF526D Om Nom and Necklace的更多相关文章
- Codeforces 526D - Om Nom and Necklace 【KMP】
ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...
- Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 526.D Om Nom and Necklace
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【Codeforces 526D】Om Nom and Necklace
Codeforces 526 D 题意:给一个字符串,求每个前缀是否能表示成\(A+B+A+B+\dots+A\)(\(k\)个\(A+B\))的形式. 思路1:求出所有前缀的哈希值,以便求每个子串的 ...
- Codeforces 526D Om Nom and Necklace (KMP)
http://codeforces.com/problemset/problem/526/D 题意 给定一个串 T,对它的每一个前缀能否写成 A+B+A+B+...+B+A+B+A+B+...+B+A ...
- Codeforces ZeptoLab Code Rush 2015 D.Om Nom and Necklace(kmp)
题目描述: 有一天,欧姆诺姆发现了一串长度为n的宝石串,上面有五颜六色的宝石.他决定摘取前面若干个宝石来做成一个漂亮的项链. 他对漂亮的项链是这样定义的,现在有一条项链S,当S=A+B+A+B+A+. ...
- 【Henu ACM Round#16 F】Om Nom and Necklace
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] KMP算法可以把"i前缀"pre[i] 分成ssssst的形式 这里t是s的前缀. 然后s其实就是pre[i]中 ...
- CodeForces 526D Om Nom and Necklace
洛谷题目页面传送门 & CodeForces题目页面传送门 给定字符串\(a\),求它的每一个前缀,是否能被表示成\(m+1\)个字符串\(A\)和\(m\)个字符串\(B\)交错相连的形式, ...
- Zepto Code Rush 2014 B - Om Nom and Spiders
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...
随机推荐
- 树莓派开启wlan功能
烧好系统之后,通过网线连接树莓派到路由器.通过ip登入系统,修改interfaces文件,添加下面内容 sudo nano /etc/network/interfacesauto wlan0allow ...
- linux机械磁盘服务器分区方案
/boot分区:用来存放与linux系统启动有关的程序,比如启动引导装载程序等,建议大小为100MB /usr分区:用来存放linux系统中的应用程序,其相关数据较多,建议大于3GB. /var分区: ...
- word 摘要
word 使用心得 定义快捷键 Tools -> Customize keyboard 自定义快捷键 cmd + L, 左对齐; cmd + R, 右对齐; cmd + E, 居中对齐 cmd ...
- js event事件绑定的方法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- git/github 代码托管图文教程
现在都流行将代码托管到github,使用版本控制工具git,现在让我们开始一步一步的将我们本地的代码托管到github上去吧 一. git的使用 1.下载git工具 2.下载好后安装时候注意要使用vi ...
- python 将excel转换成字典,并且将字典写到txt文件里
# -*- coding: utf-8 -*- #python2.7 import sys reload(sys) sys.setdefaultencoding('utf-8') from pyexc ...
- jQuery前端数据通用验证库,解放你的双手
这个简易的验证库,应该能完成90%的基本验证,包括失去焦点时的验证,以及点击提交按钮时的验证.后端的那我就无能为办了,只能是谁用就谁自个儿去写了:). 先上一段调用的代码吧,JS代码说少也不少了,就不 ...
- [转]Asp.net MVC中的ViewData与ViewBag
本文转自:http://www.cnblogs.com/wintersun/archive/2012/01/21/2328563.html 在Asp.net MVC 3 web应用程序中,我们会用到V ...
- PHP配置错误信息回报的等级
Error_reporting:配置错误信息回报的等级 1 E_ERROR 致命的运行错误 2 E_WARNING 运行时警告( ...
- 【Sql server: T-Sql 技术内幕 系列】之索引篇
本文系 T-Sql技术内幕系列读后感. 用过数据库的程序猿都知道,索引可以极大的优化sql语句的执行时间,但是您要问我,怎么减少的,我只能说:"抱歉,我也不太清楚." 带着这个疑惑 ...