CSU2188: Substring
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的更多相关文章
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- [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 ...
- substring的用法
public String substring(int beginIndex, int endIndex) 返回一个新字符串,它是此字符串的一个子字符串.该子字符串从指定的 beginIndex 处开 ...
- jQuery之常用且重要方法梳理(target,arguments,slice,substring,data,trigger,Attr)-(一)
1.jquery data(name) data() 方法向被选元素附加数据,或者从被选元素获取数据. $("#btn1").click(function(){ $(" ...
- leetcode--5. Longest Palindromic Substring
题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...
- C#和Java中的Substring()
吐槽-使用清理软件整理电脑要注意,不要清理的"太狠",不然你会受伤的! C#中的Substring() 示例 实现代码 using System;using System.Coll ...
- JavaScript中的slice,splice,substr,substring,split的区别
万恶的输入法,在sublime中会显示出繁体字,各位看官见谅. 1.slice()方法:该方法在数组和string对象中都拥有. var a = [1,2,3,4,5,6]; var s = 'thi ...
随机推荐
- 2-3 Windows下一站式开发环境anaconda搭建
D:\Users\ZHONGZHENHUA\Anaconda3\Scripts\activate.bat https://www.geforce.com/hardware/notebook-gpus/ ...
- 洛谷P4315 月下“毛景树”(树剖+线段树)
传送门 woc这该死的码农题…… 把每一条边转化为它连接的两点中深度较深的那一个,然后就可以用树剖+线段树对路径进行修改了 然后顺便注意在上面这种转化之后,树剖的时候不能搞$LCA$ 然后是几个注意点 ...
- [App Store Connect帮助]七、在 App Store 上发行(4)分阶段发布某个版本更新(iOS 和 watchOS)
当您发布您 App 的一个版本更新时,您可以选择分阶段发布您的 iOS App.如果您正在提交一个 iOS 版本更新,且您的 App 处于以下 App 状态之一,则此选项可用. 准备提交 正在等待审核 ...
- [Swift通天遁地]一、超级工具-(4)使用UIWebView(网页视图)加载HTML和Gif动画
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 洛谷P4141消失之物(背包经典题)——Chemist
题目地址:https://www.luogu.org/problemnew/show/P4141 分析:这题当然可以直接暴力枚举去掉哪一个物品,然后每次暴力跑一遍背包,时间复杂度为O(m*n^2),显 ...
- HTML中a标签自动识别电话、邮箱
HTML中a标签自动识别电话.邮箱 联系电话:<a href="tel:010-88888888">010-88888888</a><br> 联 ...
- 暴力 hihoCoder 1178 计数
题目传送门 /* 暴力:这题真是醉了,直接暴力竟然就可以了!复杂度不会分析,不敢写暴力程序.. 枚举x,在不重复的情况下+ans,超过范围直接break */ #include <cstdio& ...
- bootmanager is missing
问题描述: 在计算机管理->存储->磁盘管理中,因误操作,将D盘设置了"将分区标记为活动分区(M)",导致重启时无法无法进入系统,提示"bootmanager ...
- 大小写 unix and windows
如果你没有使用工具, 只是sqlplus对大小写不敏感. 如果你要给sql传递参数,且在windows下面就不需要考虑.如果是aix系统,最好写一样.
- XmlDocument
XmlDocument增删改查. using System; using System.Collections.Generic; using System.ComponentModel; using ...