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 ...
随机推荐
- js调用的注意项
注意将js代码写在调用的前面 这样他就知道了 自己所调用的函数是什么了
- 关于ArcGis for javascript的引用天地图
1. 在引用天地图时, 我们要自定义一个相关的比例尺转换类 const tileInfoObj = { rows: 256, cols: 256, compressionQuality: 0, ori ...
- bzoj 4813: [Cqoi2017]小Q的棋盘【树形dp】
这么简单的dp我怎么没想到x2 f为从这个点出发后回到这个点最多能走过的点,g为从这个点出发后不回到这个点最多能走过的点,注意g有两种转移:g[u][k]=max(g[u][k],f[u][k-j-1 ...
- zoj 2532 Internship【最小割】
就是求哪些边在最大流上满流,也就是找割边.把0作为t点,s向所有的1~n连流量为inf的边,其他的边按照流量连.跑一遍最大流,从s顺着有残余流量的正向边dfs打标记fr,从t顺着正向边有残余流量的反向 ...
- linux 服务器 vim编辑器打开php文件出现中文乱码
进入服务器目录 [root@VM_139_218_centos /]# cd ~ [root@VM_139_218_centos ~]# vim .vimrc 在 .vimrc 文件中写入以下代码: ...
- [Usaco2005 Feb]Feed Accounting 饲料计算
Description Farmer John is trying to figure out when his last shipment of feed arrived. Starting wit ...
- [ZPG TEST 117] 跑路【构图】
一看懵了,求一条路的长度whose二进制位中1的个数最小?什么鬼. 其实这种n这么小的图论题,应该往Floyd上想了.令f(p, i, j)为从i走长度为2^p长度的路能否到j,若能,则在一张新的图上 ...
- 计算机视觉-SIFT特征匹配进行目标转换
Lowe将SIFT算法分解为如下四步: 1. 尺度空间极值检测:搜索所有尺度上的图像位置.通过高斯微分函数来识别潜在的对于尺度和旋转不变的兴趣点. 关键点定位:在每个候选的位置上,通过一个拟合精细的模 ...
- 洛谷 P3203 [HNOI2010]弹飞绵羊 || bzoj2002
看来这个lct板子的确没什么问题 好像还可以分块做 #include<cstdio> #include<algorithm> using namespace std; type ...
- 题解报告:hdu 1228 A+B(字符串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1228 Problem Description 读入两个小于100的正整数A和B,计算A+B. 需要注意 ...