HDU 4886 TIANKENG’s restaurant(Ⅱ) ( 暴力+hash )
TIANKENG’s restaurant(Ⅱ)
Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 130107/65536 K (Java/Others)
Total Submission(s): 466 Accepted Submission(s): 153
Meanwhile, T is different from all the substrings of S. Could you help TIANKENG get the name as soon as possible?
In each test case:
Input a string S. the length of S is not large than 1000000.
Output the string t satisfying the condition.(T also only contains eight kinds of letters-------‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’.)
因为只有8个字母 。
那么先枚举长度 ( i = 1 ~ 8 )。
O(n)处理出该长度下主串存在的子串。
再枚举排列 ( j = 0 ~ i ! )判存。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <algorithm> using namespace std; typedef long long LL;
typedef pair<int,int> pii;
const int N = ;
const int M = ;
const int inf = 1e9+;
const double eps = 1e-;
bool vis[M];
char str[N];
int a[N],f[N],len; void get_s( int n , int cnt ,char *s) {
for( int i = cnt- ; i >= ; --i ){
s[i] = (n%)+'A';
n/=;
}
s[cnt] = ;
} int check( int n ) {
int tmp = ;
if( len < n ) return -;
for( int i = ; i < f[n] ; ++i ) vis[i] = false ;
for( int i = ; i < n ; ++i )
tmp = tmp * + a[i] ;
vis[tmp] = true ;
for( int i = n ; i < len ; ++i ){
tmp = ( tmp % f[n-] ) * + a[i] ;
vis[tmp] = true ;
}
for( int i = ; i < f[n] ; ++i )if(!vis[i]){
return i ;
}
return - ;
} void Run(){
scanf("%s",str); len = strlen(str);
for( int i = ; i < len ; ++i ) a[i] = str[i]-'A';
for( int i = ; i <= ; ++i ){
int res = check(i) ;
if( res == - ) continue ;
get_s(res,i,str) ;
puts(str);
return ;
}
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int tot = , m = ; f[] = ;
for( int i = ; i < ; ++i ) m *= ,f[tot++] = m ;
int _ ; scanf("%d",&_);
while( _-- ) Run();
}
HDU 4886 TIANKENG’s restaurant(Ⅱ) ( 暴力+hash )的更多相关文章
- HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs
题意: 1.找一个字符串s使得 s不是给定母串的子串 2.且s要最短 3.s在最短情况下字典序最小 hash.,,结果t掉了...加了个姿势怪异的hash值剪枝才过.. #include <cs ...
- HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)
TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- HDU 4883 TIANKENG’s restaurant
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 解题报告:一家餐馆一天中有n波客人来吃饭,第 i 波 k 客人到达的时间是 s ,离开时的时间 ...
- HDU 4883 TIANKENG’s restaurant (贪心)
链接:pid=4883">带我学习.带我飞 第一次BC,稳挂,WA n多次.今天又一次做了一下 略挫 #include <iostream> #include <cs ...
- hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】
TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- hdu 4885 TIANKENG’s travel(bfs)
题目链接:hdu 4885 TIANKENG's travel 题目大意:给定N,L,表示有N个加油站,每次加满油能够移动距离L,必须走直线,可是能够为斜线.然后给出sx,sy,ex,ey,以及N个加 ...
- HDOJ 4883 TIANKENG’s restaurant
称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Ja ...
- HDU 2920 分块底数优化 暴力
其实和昨天写的那道水题是一样的,注意爆LL $1<=n,k<=1e9$,$\sum\limits_{i=1}^{n}(k \mod i) = nk - \sum\limits_{i=1}^ ...
- hdu4886 TIANKENG’s restaurant(Ⅱ) (trie树或者模拟进制)
TIANKENG’s restaurant(Ⅱ) Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 130107/65536 K (Ja ...
随机推荐
- python车牌精确定位
#coding=utf-8 import cv2 # 使用的是HyperLPR已经训练好了的分类器 watch_cascade = cv2.CascadeClassifier('model/casca ...
- 2018-2-13-WPF-资源冻结
title author date CreateTime categories WPF 资源冻结 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 + ...
- rpmdeps - 生成 RPM 软件包依赖关系
SYNOPSIS rpmdeps {-P|--provides} {-R|--requires} FILE ... DESCRIPTION rpmdeps 根据 FILE 参数集合,生成软件包依赖关系 ...
- pip命令一般使用
pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载 1 # wget "https://py ...
- Jade To Pug过程中的一个小问题
最近在使用jade+express+typescript搭建一个博客项目,在使用jade-bootstrap项目时出现了一个问题 在使用其中的carousel时,发现其中的变量并没有转义 +carou ...
- EXCUTE JAVAScript点击事件
# Execute Javascript document.getElementsByClassName('chooseFile')[${index}].arguments[0].click(); # ...
- 前端每日实战:49# 视频演示如何用纯 CSS 创作一支诱人的冰棍
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/vrxzMw 可交互视频教程 此视频 ...
- Ubuntu下使用天河注意事项
把下载的.cgi登陆文件用文本编辑器打开,修改端口 用管理员权限打开.cgi才能绑定端口 $ gksu nautilus # browse files as root $ gksu gedit /et ...
- Ubuntu查找软件命令
查找软件: apt-cache search <your search item>
- css linear-gradient;心跳animation
css线性背景 background:linear-gradient(20deg,#ccffff,#ffcccc); transform transform:scale(1.5); transform ...