题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度。

分析:

1、预处理每个串字母个数的前缀和。

2、暴力即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-12;
inline int dcmp(double a, double b)
{
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 4000 + 10;
const int MAXT = 3025 + 10;
using namespace std;
char s1[MAXN], s2[MAXN];
struct Node{
int sum[27];
bool operator < (const Node &rhs)const{
for(int i = 0; i < 26; ++i){
if(sum[i] != rhs.sum[i]) return sum[i] < rhs.sum[i];
}
return false;
}
Node operator - (const Node &rhs)const{
Node tmp;
for(int i = 0; i < 26; ++i){
tmp.sum[i] = sum[i] - rhs.sum[i];
}
return tmp;
}
}num1[MAXN], num2[MAXN];
set<Node> st;
int main(){
scanf("%s%s", s1 + 1, s2 + 1);
int len1 = strlen(s1 + 1);
int len2 = strlen(s2 + 1);
for(int i = 1; i <= len1; ++i){
num1[i] = num1[i - 1];
++num1[i].sum[s1[i] - 'a'];
}
for(int i = 1; i <= len2; ++i){
num2[i] = num2[i - 1];
++num2[i].sum[s2[i] - 'a'];
}
int len = min(len1, len2);
bool ok = false;
for(int i = len; i >= 1; --i){
st.clear();
for(int j = 1; j + i - 1 <= len1; ++j){
st.insert(num1[j + i - 1] - num1[j - 1]);
}
for(int j = 1; j + i - 1 <= len2; ++j){
if(st.count(num2[j + i - 1] - num2[j - 1])){
ok = true;
printf("%d\n", i);
break;
}
}
if(ok) break;
}
if(!ok) printf("0\n");
return 0;
}

  

Gym 101158D(暴力)的更多相关文章

  1. Codeforces Gym 100418B 暴力

    Sum of sequencesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  2. Ice Igloos Gym - 101480I (暴力技巧)

    Problem I: Ice Igloos \[ Time Limit: 10 s \quad Memory Limit: 512 MiB \] 题意 给出\(n\)个圆,给出每个圆的坐标\(x\). ...

  3. Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维

    题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...

  4. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  5. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  6. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  7. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  8. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  9. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

随机推荐

  1. Mark Grover

    https://www.ibm.com/developerworks/cn/data/library/bd-zookeeper/

  2. Simple English

    Simple English 1. Basic English 1.1 设计原则: 1.2 基本英语单词列表850个 1.3 规则: 1.4 质疑 1.5 维基百科:基本英语组合词表 1.6 简单英文 ...

  3. Webshell免杀研究

    前言 不想当将军的士兵不是好士兵,不想getshell的Hacker不是好Hacker~有时候我们在做攻防对抗时经常会碰到可以上传webshell的地方,但是经常会被安全狗.D盾.护卫神.云锁等安全软 ...

  4. [Write-up]-pwnlab_init

    关于 下载地址点我 Flag: /root/flag.txt 放假的第一天 哔哩哔哩视频 信息收集 nmap -sn 192.168.7.1/24 Starting Nmap 7.01 ( https ...

  5. iframe切换

    iframe(locator有三种情况,可以是:定位表达式(driver.find_element_by_xpath()),frame的名称,下标index) driver.switch_to.fra ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:默认/标准按钮

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 《Java周边》IDEA 创建Gradle子项目

    1. 创建Gradle项目 新建项目选择左侧gradle,右侧选择自己jdk版本,勾选java项目,点击Next 写上GroupId组名ArtifactId项目名后点击Next 这里选择使用本地gra ...

  8. 远程服务器使用tensorboard

    1 .由于服务器上tensorboard使用的端口是6006,因此,连接ssh时,将服务器的6006端口重定向到自己机器上的16006端口: ssh -L 16006:127.0.0.1:6006 u ...

  9. axios设置请求头失效的问题

    前言:因为在使用vue-element-admin框架时遇到了设置请求头失效的问题,在后来发现是代理跨域问题,所以又简单理解了一下跨域. 出现的问题是我在axios拦截器上设置了请求头token,但是 ...

  10. Sqlserver 基本面试题

    一 单词解释(2分/个) 34分 Data 数据 Database 数据库 RDBMS 关系数据库管理系统 GRANT 授权 REVOKE 取消权限 DENY 拒绝权限 DECLARE 定义变量 PR ...