而在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. HDC2021技术分论坛:异构组网如何解决共享资源冲突?

    作者:lijie,HarmonyOS软总线领域专家 相信大家对HarmonyOS的"超级终端"比较熟悉了.那么,您知道超级终端场景下的多种设备在不同环境下是如何组成一个网络的吗?这 ...

  2. Echart显示后端mysql数据

    一.基本思想 1.将数据存储在mysql数据库中 2.后端链接数据库,将数据库中的数据保存为json格式 3.将json格式数据使用ajax传到前端JSP页面中的Echarts 二.实现的关键点 1. ...

  3. 学习java 7.11

     学习内容: 泛型定义格式:<类型> 优点:把运行时期的问题提前到编译期间:避免了强制类型转换   泛型方法:public class Fanxing { public <T> ...

  4. 数组的高阶方法map filter reduce的使用

    数组中常用的高阶方法: foreach    map    filter    reduce    some    every 在这些方法中都是对数组中每一个元素进行遍历操作,只有foreach是没有 ...

  5. 基于 vue-cli 的 lib-flexible 适配

    基于 vue-cli3.0 的 lib-flexible 适配方案 第一步:下载安装相关依赖 第二步:创建 vue.config.js 文件并配置 第三步:在 main.js 中引入 lib-flex ...

  6. oracle to_char处理日期

    select to_char(sysdate,'d') from dual;--本周第几天 select to_char(sysdate,'dd') from dual;--本月第几天 select ...

  7. Docker 生产环境之配置容器 - 自动启动容器

    原文地址 Docker 提供了重启策略,以控制容器在退出时是否自动启动,或在 Docker 重新启动时自动启动.重启策略可确保链接的容器以正确的顺序启动.Docker 建议使用重启策略,并避免使用流程 ...

  8. Type of 'this' pointer in C++

    In C++, this pointer is passed as a hidden argument to all non-static member function calls. The typ ...

  9. sax方式解析XML学习笔记

    原理:对文档进行顺序扫描,当扫描到文档(document)开始与结束,元素开始与结束.文档结束等地方 通知事件处理函数,由事件处理函数相应动作然后继续同样的扫描,直至文档结束. 优点:消耗资源比较少: ...

  10. Linux单机安装Zookeeper

    一.官网 https://zookeeper.apache.org/ 二.简介 Apache ZooKeeper致力于开发和维护开源服务器,实现高度可靠的分布式协调. ZooKeeper是一种集中式服 ...