主题链接:点击打开链接

意甲冠军:

特定2弦

选择中删除一个字符串的第一个字母,得2个字符串全然同样

问哪些位置能够选

思路:

hash求前缀后缀。然后枚举位置

#include <cstdio>
#include <algorithm>
#include<iostream>
#include<string.h>
#include <math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define mod 100000007
#define ll long long
#define N 1000050
char s[N], c[N];
vector <int> ans;
ll l1[N], r1[N], l2[N], r2[N];
int main(){
int i, j;
while(~scanf("%s",s+1)){
scanf("%s",c+1);
int len1 = strlen(s+1), len2 = strlen(c+1);
if(len1 -1 != len2){puts("0");continue;}
l1[0] = 0;
for(i = 1; i <= len1; i++) {
l1[i] = l1[i-1]*26 + s[i];
if(l1[i]>=mod) l1[i] %= mod;
}
r1[len1+1] = 0;
for(i = len1; i ; i--) {
r1[i] = r1[i+1]*26 + s[i];
if(r1[i]>=mod) r1[i] %= mod;
} l2[0] = 0;
for(i = 1; i <= len2; i++) {
l2[i] = l2[i-1]*26 + c[i];
if(l2[i]>=mod) l2[i] %= mod;
}
r2[len2+1] = 0;
for(i = len2; i ; i--) {
r2[i] = r2[i+1]*26 + c[i];
if(r2[i]>=mod) r2[i] %= mod;
}
ans.clear();
for(i = 1; i <= len1; i++) {
ll a = l1[i-1] + r1[i+1];
ll b = l2[i-1]+r2[i];
if(a==b)ans.push_back(i);
} cout<<ans.size()<<endl;
for(i = 0; i <ans.size(); i++)
printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');
}
return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

Codeforces 39J Spelling Check hash的更多相关文章

  1. Codeforces 25E Test 【Hash】

    Codeforces 25E Test E. Test Sometimes it is hard to prepare tests for programming problems. Now Bob ...

  2. CodeForces - 484BMaximum Value(hash优化)

    个人心得:周测题目,一题没出,难受得一批.这个题目做了一个半小时还是无限WR,虽然考虑到了二分答案这个点上面了, 奈何二分比较差就想用自己的优化,虽然卡在了a=k*b+c,这里但是后面结束了这样解决还 ...

  3. Codeforces 631B Print Check (思维)

    题目链接 Print Check 注意到行数加列数最大值只有几千,那么有效的操作数只有几千,那么把这些有效的操作求出来依次模拟就可以了. #include <bits/stdc++.h> ...

  4. CodeForces 631B Print Check

    对于每一个格子,看是行最后画还是列最后画.预处理一下就可以了. #include<stdio.h> #include<string.h> int n,m,k; +]; +]; ...

  5. CodeForces 631C Print Check

    排序+构造+预处理 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm ...

  6. Codeforces 631B Print Check【模拟】

    题意: 按顺序给定列和行进行涂色,输出最终得到的方格颜色分布. 分析: 记录下涂的次序,如果某个元素的横和列都被涂过,那么就选择次序最大的颜色. 代码: #include<iostream> ...

  7. Codeforces 984 扫雷check 欧几里得b进制分数有限小数判定 f函数最大连续子段

    A /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a,b) ...

  8. SharePoint Search之(五)Query spelling correction— 查询拼写纠正

     Query spelling correction 在使用搜索引擎的时候.假设一不小心输入错误,或者对于某个词语记得不太清楚,搜索引擎会自己主动纠正: 这个功能可以缩短用户的时间,很好用.在Sh ...

  9. [2019杭电多校第七场][hdu6646]A + B = C(hash)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6646 题意为求a*10x+b*10y=c*10z满足公式的任意一组解x,y,z. 因为c有可能会由a+ ...

随机推荐

  1. amazeui页面分析4

    amazeui页面分析4 一.总结 1.直接照着作者的设计思路用:例如 pet_hd_con_time pet_hd_con_map ,这是time 和 map,那我别的说不定也可以直接用,比如aut ...

  2. 动词 + to do、动词 + doing

    1. 含义有重大区别 动词+to do 与 动词 + doing,具有较大含义上的差别的动词主要有: stop finish forget 在这些单词的后面,自然 to do 表示未做的事,doing ...

  3. 关于Altium Designer的BOM,元件清单

    在生成BOM列表的时候,要记得调整BOM的表格的宽度,以免显示不全, 还有就是BOM列表一共有 comment栏 ,description栏,designator栏,footprint栏,libref ...

  4. 14、编写一个通用的Makefile

    编译test_Makefile的方法:a. gcc -o test a.c b.c对于a.c: 预处理.编译(C文件转换成汇编).汇编(汇编转换成机器码)对于b.c:预处理.编译.汇编最后链接优点:命 ...

  5. LA 3942 - Remember the Word 字典树+DP

    看题传送门:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  6. [Angular] Test component template

    Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...

  7. 应用层协议实现系列(三)——FTPserver之设计与实现

    在实现了HTTPserver之后.本人打算再实现一个FTPserver. 因为FTP协议与HTTP一样都位于应用层,所以实现原理也类似. 在这里把实现的原理和源代码分享给大家. 首先须要明白的是FTP ...

  8. libevent源码分析-介绍、安装、使用

    Libevent介绍 安装 样例 Libevent介绍 在include\event2\event.h中有关于Libevent的介绍,这里简单翻译介绍一下: Libevent是以事件为驱动的开发可扩展 ...

  9. J2EE&JavaEE概述

    来源 Sun公司在1998年发表JDK1.2版本的时候, 使用了新名称Java 2 Platform,即"Java2平台",修改后的JDK称为Java 2 Platform Sof ...

  10. 【C++竞赛 G】Lines

    Time Limit: 3s Memory Limit: 64MB 问题描述 Ljr has several lines. The lines are covered on the X axis. L ...