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 ...
随机推荐
- 【PAT甲级】1023 Have Fun with Numbers (20 分)
题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...
- 时间和日期-<Date和SimpleDateFormat>
第一步.定义一个Date //获取当前时间 Date now=new Date(); 第二步.定义一个SimpleDateFormat //规范时间格式 SimpleDateFormat date=n ...
- 页面渲染时js阻塞的解决方法
一般地,一个包含外部样式表文件和外部脚本文件的HTML载入和渲染过程是这样的: 浏览器下载HTML文件并开始解析DOM. 遇到样式表文件link[rel=stylesheet]时,将其加入资源文件下载 ...
- 转:Entity Framework 5.0 Code First全面学习
Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code Firs ...
- Django 学习 之路由层(URL)
路由层(URL) 1.路由层简单配置 (1)path方法 写固定的url. (2)re_path方法 可以正则规则 例: urlpatterns = [ path('admin/', admin.si ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:制作一个大按钮
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 【剑指Offer面试编程题】题目1373:整数中1出现的次数--九度OJ
题目描述: 亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他.问题是:求出1~13的整数中1出现的次数,并算出100~130 ...
- jqGrid 多选复选框 编辑列 方法事件
参考:https://blog.csdn.net/zsq520520/article/details/53375284?locationNum=8&fps=1
- java基础多线程
线程的创建 方式1:继承Java.lang.Thread类,并覆盖run() 方法 package com.demo.Thread; public class ThreadDemo01 extends ...
- RTL级低功耗设计
重点:门控时钟和操作数隔离 1.并行与流水的选择 并行与流水都是用面积换速度,但是有时可以降低功耗 并行处理常用于数字信号处理部分,采用并行处理,也已降低系统工作频率从而降低功耗 用两个乘法器取代原设 ...