【noip模拟】Fancy Signal Translate (暴力 + 哈希)
题目描述
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 (暴力 + 哈希)的更多相关文章
- 【NOIP模拟】Grid(字符串哈希)
题目背景 SOURCE:NOIP2016-RZZ-1 T3 题目描述 有一个 2×N 的矩阵,矩阵的每个位置上都是一个英文小写字符. 现在需要从某一个位置开始,每次可以移动到一个没有到过的相邻位置,即 ...
- noip模拟赛 柜(暴力)
分析:暴力的方法是非常显然的,从起点走一次,从终点走一次,路径相交的点即为所求,但是这样存图都很难存下,而且如果数据极端可能要求R*C次,时间空间都受不了.如果不需要记录整张图,并且一次能移动很多步就 ...
- 【noip模拟赛4】Matrix67的派对 暴力dfs
[noip模拟赛4]Matrix67的派对 描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们 ...
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
- 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题, ...
- 10.16 NOIP模拟赛
目录 2018.10.16 NOIP模拟赛 A 购物shop B 期望exp(DP 期望 按位计算) C 魔法迷宫maze(状压 暴力) 考试代码 C 2018.10.16 NOIP模拟赛 时间:2h ...
随机推荐
- 洛谷—— P1069 细胞分裂
https://www.luogu.org/problem/show?pid=1069#sub 题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家.现在,他正在为一个细 ...
- 算法中的优化问题(optimization problem)
和多数算法不同的是,有些问题的答案不只一个,而是需要在多个答案中,按照一定标准选出"最佳"答案,这类问题就统称为"优化问题"(optimization prob ...
- 【Codeforces Round #445 (Div. 2) D】Restoration of string
[链接] 我是链接,点我呀:) [题意] 给你n个字符串. 让你构造一个字符串s. 使得这n个字符串. 每个字符串都是s的子串. 且都是出现次数最多的子串. 要求s的长度最短,且s的字典序最小. [题 ...
- 在 Swift 项目中实现侧滑菜单-利用 SWRevealViewController
你可以完全自己手动写一个侧滑菜单,但是现在在 GitHub 上面已经有很多免费的开源库了,如果不是有很特别的需求,大可不必新建一个轮子. 在这里我使用的这个第三方库名字叫做 SWRevealViewC ...
- AE 向已存在的要素类中添加字段
风过无痕 原文向已存在的要素类中添加字段 以前,在用AE写程序的时候,为了方便,一般都是直接新建一个MapControl窗体应用程序.这次需要解决的问题用不到窗口,就突发奇想,直接新建了一个Conso ...
- 七步从AngularJS菜鸟到专家(7):Routing
这是"AngularJS – 七步从菜鸟到专家"系列的第七篇. 在第一篇,我们展示了如何開始搭建一个AngularaJS应用.在第四.五篇我们讨论了Angular内建的directives.上一篇了解 ...
- linux下查看动态链接库依赖关系的命令 x86: ldd *.so arm: arm-linux-readelf -d *.so 实际例子: 以项目中用到的库librtsp.so分析: lijun@ubuntu:~/workspace$ arm-hisiv100nptl-linux-ld -d librtsp.so arm-hisiv100nptl-linux-ld:
linux下查看动态链接库依赖关系的命令 x86:ldd *.so arm:arm-linux-readelf -d *.so 实际例子:以项目中用到的库librtsp.so分析:l ...
- [Angular2 Form] Reactive form: valueChanges, update data model only when form is valid
For each formBuild, formControl, formGroup they all have 'valueChanges' prop, which is an Observable ...
- swift入门之TableView
IOS8更新了,oc还将继续但新增了swift语言,能够代替oc编写ios应用,本文将使用swift作为编写语言,为大家提供step by step的教程. 工具 ios每次更新都须要更新xcode, ...
- matplotlib学习之函数积分图
# coding:utf-8 import numpy as np from matplotlib import pyplot as plt from matplotlib.patches impor ...