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 ...
随机推荐
- 如何启动mac版docker自带的k8s
最近准备好好学习下k8s,为了图方便,直接使用docker集成的k8s,但是网上找了一些教程但都没能一次性成功,只好自己从头跑一遍,顺手写个教程可以方便有类似需求的同学参考. 话不多说,直接上步骤. ...
- Day11 - N - Game HDU - 3389
题目链接 题意是说有1到n个标号的盒子,选择一个非空的盒子A,B是否空无所谓,满足(A+B)%2=1,(A+B)%3=0,A>B 解上面的同余方程组,最小解为3,循环为2*3=6,那我们可以把前 ...
- Java 正则?:?=?!的理解
上图是官方文档的介绍,总结一下讲了两个知识点 ①是否获取匹配并保存匹配的值.②正向预查和反向预查. 1:解释是否获取匹配并保存匹配的值 ()表示捕获分组,获取匹配,()把每个分组里的匹配的值保存起来 ...
- 读取json文件
//读取json文件 var obji = File.ReadAllText(@"E:\test.json"); var resultdata = JsonConvert.Dese ...
- Scrapy 框架结构及工作原理
1.下图为 Scrapy 框架的组成结构,并从数据流的角度揭示 Scrapy 的工作原理 2.首先.简单了解一下 Scrapy 框架中的各个组件 组 件 描 述 类 型 EN ...
- JavaScript 中 new 关键字结合构造函数创建对象
步骤: new会在内存中创建一个新的空对象 new 会让this指向这个新的对象 执行构造函数(给这个新对象添加属性和方法) new会返回这个新对象
- Broadcast机制(二)
内容提纲: 在本节课当中,我会继续为大家讲解Android的广播机制,重点内容有以下的两个方面: a) 在应用程序当中注册BroadcastReceiver的方法 b) ...
- Java HotSpot(TM) Client VM 与 server VM 的配置
在Linux 6.5 下安装Elasticsearch 出现错误: JVM is using the client VM [Java HotSpot(TM) Client VM] but should ...
- JVM中 Class 文件分析
Java 虚拟机中定义的 Class 文件格式.每一个 Class 文件都对应着唯一一个类 或接口的定义信息,但是相对地,类或接口并不一定都得定义在文件里(譬如类或接口也可以通过 类加载器直接生成). ...
- JAVA 集合 List 分组的两种方法
CSDN日报20170219--<程序员的沟通之痛> [技术直播]揭开人工智能神秘的面纱 程序员1月书讯 云端应用征文大赛,秀绝招,赢无人机! JAVA 集合 List 分组的两种方法 2 ...