题目描述

FST是一名可怜的 OIer,他很强,但是经常 fst,所以 rating 一直低迷。

但是重点在于,他真的很强!他发明了一种奇特的加密方式,这种加密方式只有OIer
才能破解。

这种加密方式是这样的:对于一个 01 串,他会构造另一个 01 串,使得原串是在新串中没有出现过的最短的串。

现在 FST 已经加密好了一个串,但是他的加密方式有些 BUG ,导致没出现过的最短的串不止一个,他感觉非常懊恼,所以他希望计算出没出现过的最短的串的长度。

输入格式

一行,一个 01 串。

输出格式

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

样例数据 1

输入

100010110011101

输出

4

备注

【数据范围】
测试点 1、2、3 的串长度≤10;
测试点 3、4、5 的串长度≤100;
测试点 6、7、8、9、10 的串长度≤10^5;

题目分析

注意到$2^{20}$左右已经超过maxn了,所以肯定不会枚举完所有情况。

先将每个点放入队列,然后每次都往后加一个字符,这样之前必定要删除最后一个点(末尾没有可加入的字符),然后将队列中的每个字符串算出hash,去重计数,如果cnt < $2^{len}$,那么就输出len即为答案。

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
using namespace std; const int N = 1e5 + ;
string s;
string t[N];
int pos[N];
int cnt;
int hashVal[N];
bool hash[N];
typedef long long ll;
ll pow2[]; inline int read(){
int i = , f = ; char ch = getchar();
for(; (ch < '' || ch > '') && ch != '-'; ch = getchar());
if(ch == '-') f = -, ch = getchar();
for(; ch >= '' && ch <= ''; ch = getchar())
i = (i << ) + (i << ) + (ch - '');
return i * f;
} inline void wr(int x){
if(x < ) putchar('-'), x = -x;
if(x > ) wr(x / );
putchar(x % + '');
} inline void initPow2(){
pow2[] = ;
for(int i = ; i <= ; i++)
pow2[i] = pow2[i - ] * ;
} int main(){
initPow2();
cin >> s;
int len = s.length();
string tmp = "";
for(int i = ; i < len; i++)
t[i] = "", pos[i] = i - , hashVal[i] = ;
cnt = len;
int leng = ;
while(cnt){
memset(hash, , sizeof hash);
leng++; int ans = ;
for(int i = ; i < cnt; i++){
t[i] += s[++pos[i]];
hashVal[i] *= ;
if(s[pos[i]] == '')
hashVal[i]++;
int h = hashVal[i];
if(!hash[h]) ans++, hash[h] = true;
}
if(ans < pow2[leng]){
wr(leng);
return ;
}
cnt--;
}
wr();
return ;
}

【noip模拟】Fancy Signal Translate (暴力 + 哈希)的更多相关文章

  1. 【NOIP模拟】Grid(字符串哈希)

    题目背景 SOURCE:NOIP2016-RZZ-1 T3 题目描述 有一个 2×N 的矩阵,矩阵的每个位置上都是一个英文小写字符. 现在需要从某一个位置开始,每次可以移动到一个没有到过的相邻位置,即 ...

  2. noip模拟赛 柜(暴力)

    分析:暴力的方法是非常显然的,从起点走一次,从终点走一次,路径相交的点即为所求,但是这样存图都很难存下,而且如果数据极端可能要求R*C次,时间空间都受不了.如果不需要记录整张图,并且一次能移动很多步就 ...

  3. 【noip模拟赛4】Matrix67的派对 暴力dfs

    [noip模拟赛4]Matrix67的派对   描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们 ...

  4. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  5. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  6. CH Round #49 - Streaming #4 (NOIP模拟赛Day2)

    A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...

  7. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  8. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)

    A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...

  9. 10.16 NOIP模拟赛

    目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...

随机推荐

  1. uva 10098 Generating Fast(全排列)

    还是用的两种方法,递归和STL,递归那个是含有反复元素的全排列,这道题我 没有尝试没有反复元素的排列,由于从题目上并没有发现一定是有反复元素的() 贴代码: <span style=" ...

  2. 最新GitHub新手使用教程(Linux/Ubuntu Git从安装到使用)——详细图解

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.叙述 1.说明:需要在Windows 安装Git的同学,可以查看该篇博客 https://blog.csdn.net/qq_4 ...

  3. StackExchange.Redis 官方文档(六) PipelinesMultiplexers

    原文:StackExchange.Redis 官方文档(六) PipelinesMultiplexers 流水线和复用 糟糕的时间浪费.现代的计算机以惊人的速度产生大量的数据,而且高速网络通道(通常在 ...

  4. [React] Close the menu component when click outside the menu

    Most of the time, your components respond to events that occur within the component tree by defining ...

  5. andriod first app-computer

    andriod first app-computer 个人信息:就读于燕大本科软件project专业 眼下大三; 本人博客:google搜索"cqs_2012"就可以; 个人爱好: ...

  6. Codeforces Round #Pi (Div. 2) B Berland National Library

    B. Berland National Library time limit per test1 second memory limit per test256 megabytes inputstan ...

  7. Qt没有被正确安装,请运行make install问题的解决

    在网上直接下载别人编译好的Qt库,为自己使用省了不少事.但往往也会遇到些问题,其中Qt version is not properly installed,please run make instal ...

  8. SQLITE3 使用总结(直接使用C函数)

    转载网址:http://blog.chinaunix.net/uid-8447633-id-3321394.html 前序: Sqlite3 的确很好用.小巧.速度快.但是因为非微软的产品,帮助文档总 ...

  9. js进阶 12-5 jquery中表单事件如何使用

    js进阶 12-5 jquery中表单事件如何使用 一.总结 一句话总结:表单事件如何使用:可元素添加事件监听,然后监听元素,和javase里面一样. 1.表单获取焦点和失去焦点事件有哪两组? 注意是 ...

  10. php实现删除链表中重复的节点

    php实现删除链表中重复的节点 一.总结 二.php实现删除链表中重复的节点 题目描述: 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1 ...