zoukankan      html  css  js  c++  java
  • 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。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<stack>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 #define enter puts("")
    13 #define space putchar(' ')
    14 #define Mem(a, x) memset(a, x, sizeof(a))
    15 #define rg register
    16 typedef long long ll;
    17 typedef double db;
    18 const int INF = 0x3f3f3f3f;
    19 const db eps = 1e-8;
    20 const int maxn = 1e6 + 5;
    21 inline ll read()
    22 {
    23   ll ans = 0;
    24   char ch = getchar(), las = ' ';
    25   while(!isdigit(ch)) las = ch, ch = getchar();
    26   while(isdigit(ch)) ans = ans * 10 + ch - '0', ch = getchar();
    27   if(las == '-') ans = -ans;
    28   return ans;
    29 }
    30 inline void write(ll x)
    31 {
    32   if(x < 0) putchar('-'), x = -x;
    33   if(x >= 10) write(x / 10);
    34   putchar(x % 10 + '0');
    35 }
    36 
    37 int n, k;
    38 char s[maxn];
    39 int f[maxn];
    40 
    41 void init()
    42 {
    43   for(int i = 2, j = 0; i <= n; ++i)
    44     {
    45       while(j && s[j + 1] != s[i]) j = f[j];
    46       if(s[j + 1] == s[i]) j++;
    47       f[i] = j;
    48     }
    49 }
    50 
    51 bool work(int i, int cir)
    52 {
    53   int x = i / cir;
    54   if(i % cir) return x / k > x % k;
    55   else return x / k >= x % k;
    56 }
    57 
    58 int main()
    59 {
    60   n = read(), k = read();
    61   scanf("%s", s + 1);
    62   init();
    63   for(int i = 1; i <= n; ++i) write(work(i, i - f[i]));
    64   enter;
    65   return 0;
    66 }
    View Code
  • 相关阅读:
    HTML 网页创建
    CSS3 opacity
    两数相加的和
    九九乘法表
    Linux下的Makefile初入
    linux 下定义寄存器宏 实现类似于STM32的寄存器操作
    Linux 编译与交叉编译
    linux IMX6 汇编点亮一个LED灯
    Linux基本指令与作用
    C# Task 源代码阅读(2)
  • 原文地址:https://www.cnblogs.com/mrclr/p/9765091.html
Copyright © 2011-2022 走看看