Gym 101158D(暴力)
题意:给定两个长度为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(暴力)的更多相关文章
- Codeforces Gym 100418B 暴力
Sum of sequencesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...
- Ice Igloos Gym - 101480I (暴力技巧)
Problem I: Ice Igloos \[ Time Limit: 10 s \quad Memory Limit: 512 MiB \] 题意 给出\(n\)个圆,给出每个圆的坐标\(x\). ...
- Consonant Fencity Gym - 101612C 暴力二进制枚举 Intelligence in Perpendicularia Gym - 101612I 思维
题意1: 给你一个由小写字母构成的字符串s,你可以其中某些字符变成大写字母.如果s中有字母a,你如果想把a变成大写,那s字符串中的每一个a都要变成A 最后你需要要出来所有的字符对,s[i]和s[i-1 ...
- 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 ...
- ACM: Gym 100935G Board Game - DFS暴力搜索
Board Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Gym 100 ...
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
随机推荐
- webpack的配置文件[webpack.config.js]
如果项目里没有webpack.config.js这个文件,webpack会使用它本身内置在源码里的配置项. webpack.config.js这个配置名称可以通过指令修改 npx webpack -- ...
- Day1-A-POJ-3295
由题意知,有5种操作,5个未知数,可0可1,一串操作问是否恒为1,最多100个字符,直接栈模拟所有情况即可 代码如下: int p, q, r, s, t; bool calculate(string ...
- Scrapy采集某小说网站的全部小说
链接: https://pan.baidu.com/s/1hrgYDzhgQIDrf4KmZxhW1w 密码: h1m6 源码以及运行图
- VS2010解决闪退的方法
VS2010解决闪退的原因 前言 在利用vs2010编译器进行编写程序的时候程序结果无法看到,针对上述问题有如下两个解决方法: 方法1. 在程序结束之前(return之前)加 system(&quo ...
- StringUtils工具类常用方法汇总:判空、转换、移除、替换、反转。
Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的方法总 ...
- JuJu Beta Postmortem
JuJu demo demo 项目github地址 JuJu 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 完成基于Julia语言的NER mod ...
- lvextend 扩容后, df -h 看到的却还是原来的大小
[root@stb ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/vg_stb-lv ...
- main.js index.html与app.vue三者关系详解
main.js index.html与app.vue三者关系详解 2019年01月23日 11:12:15 Pecodo 阅读数 186 main.js与index.html是nodejs的项目启 ...
- acid-事务的原子性、一致性、隔离性、持久性
博客分类: oracle-dba 原子性 多个事情组成一个单元,要么同时成功或失败,不能只运行其中一个 一致性 事务处理要将数据库从一种状态转变为另一种状态. 一旦提交了修改数据,那么其它人读 ...
- MySQL 加密 压缩
许多MySQL加密和压缩函数返回结果可能包含任意字节值的字符串,如果要存储这些结果,请使用VARBINARY或BLOB二进制字符串数据类型.这将避免使用非二进制字符串数据类型(CHAR, VARCHA ...