Description

FST 是一名可怜的 ACMer,他很强,但是经常 fst,所以 rating 一直低迷。 但是重点在于,他真的很强!他发明了一种奇特的加密方式,这种加密方式只有 ACMer 才能破解。 这种加密方式是这样的:对于一个 01 串,他会构造另一个 01 串,使得原串是在新串 中没有出现过的最短的串。 现在 FST 已经加密好了一个串,但是他的加密方式有些 BUG,导致没出现过的最短的 串不止一个,他感觉非常懊恼,所以他希望计算出没出现过的最短的串的长度。

Input

单组数据 一行,一个 01 串,字符串串长小于等于10^ 5

Output

一行,一个正整数,表示没有出现过的最短串的长度

Sample Input

100010110011101

Sample Output

4

题意:在一个很长的串内找到一个没有出现过最短的子串,由于串比较长,所以我们不能直接对于字符串进行处理。我们可以换一个思想,从答案的长度入手,每次枚举答案的长度,然后把这个很长的子串拆分很多这个长度的子串,
放到set当中存储,利用set的去重,如果最后的set的size()<2^(ans)也就是小于我们枚举长度能产生所有的可能的串的数量,那么就说明当中肯定有一个串没有出现过。
就可以得到答案。 这题也可以用字符串hash去做,时间复杂度会比set+string的要小些。但是思想是一样的。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std; string s;
set<string>ss;
int main()
{
cin>>s;
int len=s.length();
string temp="";
int ans=1;
while(1)
{
ss.clear();
for(int i=0;i<=len-ans;i++)
{
// cout<<i<<endl;
for(int j=i;j<i+ans;j++)
{
temp+=s[j];
}
// cout<<temp<<endl;
ss.insert(temp);
temp="";
}
// cout<<ss.size()<<endl;
if(ss.size()<pow(2,ans))
break;
else
ans++;
}
printf("%d\n",ans);
return 0;
} /**********************************************************************
Problem: 2188
User: therang
Language: C++
Result: AC
Time:540 ms
Memory:3580 kb
**********************************************************************/

  

CSU2188: Substring的更多相关文章

  1. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  2. 最长回文子串-LeetCode 5 Longest Palindromic Substring

    题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  3. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  4. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  5. substring的用法

    public String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串.该子字符串从指定的 beginIndex 处开 ...

  6. jQuery之常用且重要方法梳理(target,arguments,slice,substring,data,trigger,Attr)-(一)

    1.jquery  data(name) data() 方法向被选元素附加数据,或者从被选元素获取数据. $("#btn1").click(function(){ $(" ...

  7. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

  8. C#和Java中的Substring()

    吐槽-使用清理软件整理电脑要注意,不要清理的"太狠",不然你会受伤的! C#中的Substring() 示例 实现代码 using System;using System.Coll ...

  9. JavaScript中的slice,splice,substr,substring,split的区别

    万恶的输入法,在sublime中会显示出繁体字,各位看官见谅. 1.slice()方法:该方法在数组和string对象中都拥有. var a = [1,2,3,4,5,6]; var s = 'thi ...

随机推荐

  1. Extjs4 登陆界面

    原文地址:http://fengxinnl.iteye.com/blog/1950585 <script src="ext4.2/bootstrap.js" type=&qu ...

  2. E20170524-hm

    logging   n. <美>伐木搬运业; 记录,存入; 航行日志; inversion  n. 倒置; 转化; (尤指词序) 倒装; (染色体的) 倒位; reversion   n. ...

  3. NetBeans IDE For PHP 简体中文版 8.1安装配置

    一.NetBeans IDE For PHP简介 NetBeans IDE 是一个开发环境 - 供程序员编写.编译.调试和部署程序的一个工具. 它是用 Java 编写的 - 但却可以支持任何编程语言. ...

  4. bzoj P1979 华容道【bfs+spfa】

    调死我了-- 首先观察移动方式,需要移动的格子每次移动到相邻格子,一定是先把空白格子挪过去,所以我们得到一种做法,就是bfs预处理出每一个格子的四联通格子之间的空白格子移动距离建边,注意这个移动是不能 ...

  5. bzoj 1006: [HNOI2008]神奇的国度【弦图+LesBFS】

    参考论文:https://wenku.baidu.com/view/6f9f2223dd36a32d73758126.html 参考代码:http://hzwer.com/3500.html 虽然会写 ...

  6. 【SpringCloud构建微服务系列】Feign的使用详解

    一.简介 在微服务中,服务消费者需要请求服务生产者的接口进行消费,可以使用SpringBoot自带的RestTemplate或者HttpClient实现,但是都过于麻烦. 这时,就可以使用Feign了 ...

  7. win7 右键菜单残影 消除方法

    1. 治标法: 右键桌面->更改分辨率  随便换一个分辨率再还原就OK了! 2. 根治法: 我的电脑-> 属性 ->高级选项-> 高级-> 设置-> 自定义   不 ...

  8. js中toFixed重写

    在测试原生的toFixed发现,它在个浏览器上表现不一致,并且有些值在保留小数时得到的结果并不是想要,如在chrome下测试: 所以针对toFixed方法不准的问题,我们进行方法改造: 主要思路是:对 ...

  9. MVP架构模式

    概念解释 MVP是Model(数据) View(界面) Presenter(表现层)的缩写,它是MVC架构的变种,强调Model和View的最大化解耦和单一职责原则 Model:负责数据的来源和封装, ...

  10. poj1781In Danger(约瑟夫) 问题

    链接 之前队内赛中的一道题目 当时怎么想也没想到,就一直放到了今天,刚才看另一题的讲解突然看到时拿这个题作为引子来讲的,就仔细看了下. 参考<<具体数学>> p7. Josep ...