HDU4886 TIANKENG’s restaurant(Ⅱ)(哈希)
来源:互联网 发布:php7不支持mysql 编辑:程序博客网 时间:2024/06/05 04:31
题意:
一个字符串有许多子串 现要找出最短的字典序最小的不是它的子串的串 这个长串只有A~H字母
分析:
首先估计下答案的最长长度,如果答案的长度为7,那么字符串种类就有8^7种,已经超过了所给字符串的最大长度1000000。那么只需要枚举长度 利用哈希判定字符串出现的问题。
#include<bits/stdc++.h>using namespace std;const int maxn = 1000010;char str[maxn];int Hash[maxn], vis[maxn];int main(){ int T, i, j, len; scanf("%d", &T); while(T--) { scanf("%s", str+1); len = strlen(str+1); memset(Hash, 0, sizeof(Hash)); memset(vis, 0, sizeof(vis)); int lim = 8, ans; for(i = 1; i <= 7; i++) { for(j = len; j >= i; j--) { Hash[j] = Hash[j-1]*8 + str[j] - 'A'; vis[Hash[j]]++; } for(j = 0; j < lim; j++) { if(!vis[j]) { ans = j; goto gt; } vis[j] = 0; } lim *= 8; } gt: j = 0; while(i--) { str[j++] = ans % 8 + 'A'; ans /= 8; } for(i = j - 1; i >= 0; i--) printf("%c", str[i]); puts(""); } return 0;}
阅读全文
0 0
- HDU4886 TIANKENG’s restaurant(Ⅱ)(哈希)
- HDU 4886 TIANKENG’s restaurant(Ⅱ) (哈希)
- HDU 4886 TIANKENG’s restaurant(Ⅱ) (枚举 哈希)
- hdu 4886 TIANKENG’s restaurant(Ⅱ) 字符串
- HDU 4886 TIANKENG’s restaurant(Ⅱ)
- TIANKENG’s restaurant
- TIANKENG’s restaurant
- HDU_4883 TIANKENG’s restaurant
- hdu TIANKENG’s restaurant
- hdoj4883 TIANKENG’s restaurant
- TIANKENG’s restaurant
- HDOJ TIANKENG’s restaurant
- TIANKENG’s restaurant
- 4883 TIANKENG’s restaurant
- hd4883 TIANKENG’s restaurant
- TIANKENG’s restaurant--hdu4883
- TIANKENG’s restaurant
- B - TIANKENG’s restaurant
- php关于支付宝支付的探讨
- javascrip之数组
- 卢俊卿:幸福城市当以人为本
- java-SE-7
- linux系统中不同颜色的文件夹及根目录介绍
- HDU4886 TIANKENG’s restaurant(Ⅱ)(哈希)
- Java中ArrayList详解与练习
- Pentaho Kettle解决方案:使用PDI构建开源ETL解决方案pdf
- 有趣的一道题
- JaveScript之数组实训案例
- 389. Find the Difference
- MFC的学习笔记(一)
- AndroidStudio 中如何查看获取MD5和SHA1值(应用签名)
- pthread_cond_wait()用法分析