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 ...
随机推荐
- mpvue 无法获取$store的问题
在开发的时候,我们喜欢将一些公共的方法,属性,放在一个特定的位置,例如在mpvue开发小程序的时候, 我们将其放在 vue提供的store里面,或者在mainjs中通过Vue.prototype.xx ...
- vue,一路走来(5)--微信登录
微信登录 今天又是周末了,想着博客还没记录完成.是的,下面记录一下微信登录遇到的问题. 在我的项目中,个人中心是需要完成授权登录才可以访问的,首先在定义路由的时候就需要多添加一个自定义字段requir ...
- yara规则的二进制漏洞
https://www.anquanke.com/post/id/147675 yara32.exe 后缀.yar
- QT + openssl + VS2015静态编译
从http://slproweb.com/products/Win32OpenSSL.html下载已经编译好的openssl,一路next 我将OpenSSL-Win32\lib\VC目录下的libe ...
- BZOJ2839 集合计数 二项式反演
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2839 题解 二项式反演板子题. 类似于一般的容斥,我们发现恰好 \(k\) 个不怎么好求,但是 ...
- Ubuntu18.04 安装 Idea 2018.2
https://blog.csdn.net/weixx3/article/details/81136822 Ubuntu18.04 安装 Idea 2018.2环境信息:OS:Ubuntu18.04J ...
- vue 防止xss攻击
1.在终端引入xss,命令: npm install xss --save 2.在vue的页面进行引入 import xss from 'xss' 测试 <p v-html="test ...
- java 比较两个日期大小(2) 用before(), after()
调试代码,我就不整理了,记下after() before() 觉得这张图好美,从人家的博客上截的,找不到链接了
- HTTP协议缓存
缓存的概念 缓存这个东西真的是无处不在, 有浏览器端的缓存, 有服务器端的缓存,有代理服务器的缓存, 有ASP.NET页面缓存,对象缓存. 数据库也有缓存, 等等. http中具有缓存功能的是浏览器缓 ...
- boost datetime
To create a date, use the class boost::gregorian::date 1. date #include <boost/date_time/gregoria ...