而在26以内且属于fibonacci数列的数为1,2,3,5,8,13,21时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Given a string consisting of only lower case letters, output all its lucky non-empty substrings in lexicographical order. Same substrings should be printed once.

输入

A string consisting no more than 100 lower case letters.

输出

Output the lucky substrings in lexicographical order, one per line. Same substrings should be printed once.

样例输入
aabcd
样例输出
a
aa 
aab 
aabc 
ab 
abc 
bc 
bcd 
cd 
d
思路:暴力枚举。26以内斐波那契数打下表就可以了。用set去重排序。复杂度O(n*n*n);
我用前缀和,感觉并没有优化。
  1 #include<stdio.h>  2 #include<algorithm>  3 #include<iostream>  4 #include<string.h>  5 #include<stdlib.h>  6 #include<math.h>  7 #include<cstdio>  8 #include<queue>  9 #include<stack> 10 #include<map> 11 #include<set> 12 using namespace std; 13 char cou[200]; 14 int fei[30]; 15 int flag[30]; 16 char dd[200]; 17 set<string>my; 18 set<string>::const_iterator it; 19 typedef struct pp 20 { 21     int al[26]; 22     pp() 23     { 24         memset(al,0,sizeof(al)); 25     } 26 } ss; 27  28 int main(void) 29 { 30     int n,i,j,k,p,q; 31     fei[1]=1; 32     fei[2]=1; 33     for(i=3; i<30; i++) 34     { 35         fei[i]=fei[i-1]+fei[i-2]; 36         if(fei[i]>=26) 37         { 38             break; 39         } 40     } 41     int zz=i; 42     for(i=1; i<zz; i++) 43         flag[fei[i]]=1; 44     while(scanf("%s",cou)!=EOF) 45     { 46         my.clear(); 47         ss ak[200]; 48         int l=strlen(cou); 49         int cnt=0; 50         ak[cnt].al[cou[0]-'a']++; 51         for(i=1; i<l; i++) 52         { 53             ak[i].al[cou[i]-'a']++; 54             for(j=0; j<26; j++) 55             { 56                 ak[i].al[j]+=ak[i-1].al[j]; 57             } 58         } 59         int yy[26]; 60         for(i=0; i<l; i++) 61         { 62             for(int s=0; s<26; s++) 63             { 64                 yy[s]=ak[i].al[s]; 65             } 66             int ans=0; 67             for(int s=0; s<26; s++) 68             { 69                 if(yy[s]) 70                 { 71                     ans++; 72                 } 73  74             } 75             if(flag[ans]) 76             { 77                 memset(dd,0,sizeof(dd)); 78                 int z=0; 79                 int s; 80                 for( s=0; s<=i; s++) 81                 { 82                     dd[z++]=cou[s]; 83                 } 84                 my.insert(dd); 85  86             } 87         } 88         for(i=0; i<l; i++) 89         { 90             for(j=i+1; j<l; j++) 91             { 92                 for(int s=0; s<26; s++) 93                 { 94                     yy[s]=ak[j].al[s]-ak[i].al[s]; 95                 } 96                 int ans=0; 97                 for(int s=0; s<26; s++) 98                 { 99                     if(yy[s])100                     {101                         ans++;102                     }103 104                 }105                 if(flag[ans])106                 {107                     memset(dd,0,sizeof(dd));108                     int z=0;109                     int s;110                     for( s=i+1; s<=j; s++)111                     {112                         dd[z++]=cou[s];113                     }114                     my.insert(dd);115                 }116             }117         }118         for(it=my.begin(); it!=my.end(); it++)119         {120             cout<<*it<<endl;121         }122     }123     return 0;124 }

Lucky Substrings的更多相关文章

  1. hihocoder 1152 Lucky Substrings

    #1152 : Lucky Substrings 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if t ...

  2. 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...

  3. hihocoder #1152 Lucky Substrings 【字符串处理问题】strsub()函数+set集合去重

    #1152 : Lucky Substrings时间限制:10000ms单点时限:1000ms内存限制:256MB描述A string s is LUCKY if and only if the nu ...

  4. Lucky String

    Lucky String -- 微软笔试 标签(空格分隔): 算法 A string s is LUCKY if and only if the number of different charact ...

  5. 【每天一道算法题】Lucky String

    A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi ...

  6. lucky 的 时光助理(2)

    lucky小姐说:昨天晚上他喝醉了,发消息说他想我了,说他后悔了. 我很惊讶. 我问lucky:你们很久都没有联系, 突然说... 你怎么想. 没错,'他'就是lucky的前男友. lucky看着我, ...

  7. lucky 的 时光助理

    2017年的lucky小姐,厌倦了现在的工作,她觉得这些的工作对于她而言不具备挑战性,她在迷茫春节过后该如何选择, 这里是距她走出校门整整一年的时光. lucky小姐从开发走向了实施,目的是想周游这个 ...

  8. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  9. ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)

    ZOJ3944 People Counting ZOJ3939 The Lucky Week 1.PeopleConting 题意:照片上有很多个人,用矩阵里的字符表示.一个人如下: .O. /|\ ...

随机推荐

  1. 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享二:问题1

    框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 添加时,如果失败,不能正确跳转 c ...

  2. [源码解析] PyTorch 分布式 Autograd (6) ---- 引擎(下)

    [源码解析] PyTtorch 分布式 Autograd (6) ---- 引擎(下) 目录 [源码解析] PyTtorch 分布式 Autograd (6) ---- 引擎(下) 0x00 摘要 0 ...

  3. 从零构建Java项目(Maven+SpringBoot+Git) #02 奥斯丁项目

    前两天我说要写个项目来持续迭代,有好多小伙伴都表示支持和鼓励,项目的第一篇这不就来了么~我给项目取了个名字,英文名叫做:austin,中文名叫做:奥斯丁 名字倒没有什么特别的含义,我单纯觉得这个名字好 ...

  4. 学习Java 2021/10/7

    java重写Override 重载Overload 重写是子类对父类的允许访问的方法的实现过程进行重新编写,返回值和形参都不能改变.即外壳不变,核心重写 重写规则: 参数列表与被重写方法的参数列表必须 ...

  5. day02 web主流框架

    day02 web主流框架 今日内容概要 手写简易版本web框架 借助于wsgiref模块 动静态网页 jinja2模板语法 前端.web框架.数据库三种结合 Python主流web框架 django ...

  6. 重磅丨腾讯云开源业界首个 etcd 一站式治理平台 Kstone

    ​ Kstone 开源 在 CNCF 云原生基金会举办的2021年12月9日 KubeCon China大会上,腾讯云容器 TKE 团队发布了 Kstone etcd 治理平台开源项目. Kstone ...

  7. matplotlib画3d图

    import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D fig = plt.f ...

  8. 过滤敏感词工具类SensitiveFilter

    网上过滤敏感词工具类有的存在挺多bug,这是我自己改用的过滤敏感词工具类,目前来说没啥bug,如果有bug欢迎在评论指出 使用前缀树 Trie 实现的过滤敏感词,树节点用静态内部类表示了,都写在一个 ...

  9. Python用xlrd读取Excel数据到list中再用xlwt把数据写入到新的Excel中

    一.先用xlrd读取Excel数据到list列表中(存入列表中的数据如下图所示) import xlrd as xd #导入需要的包 import xlwt data =xd.open_workboo ...

  10. Flutter 2.8 更新详解

    北半球的冬意已至,黄叶与气温均随风而落.年终的最后一个 Flutter 稳定版本 已悄然来到你的面前.让我们向 Flutter 2.8 打声招呼- 本次更新包含了 207 位贡献者和 178 位审核者 ...