题干:

BaoBao has just found two strings  and  in his left pocket, where  indicates the -th character in string , and  indicates the -th character in string .

As BaoBao is bored, he decides to select a substring of  and reverse it. Formally speaking, he can select two integers  and  such that  and change the string to .

In how many ways can BaoBao change  to  using the above operation exactly once? Let  be an operation which reverses the substring , and  be an operation which reverses the substring . These two operations are considered different, if  or .

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains a string  (), while the second line contains another string  (). Both strings are composed of lower-cased English letters.

It's guaranteed that the sum of  of all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the answer.

Sample Input

2
abcbcdcbd
abcdcbcbd
abc
abc

Sample Output

3
3

Hint

For the first sample test case, BaoBao can do one of the following three operations: (2, 8), (3, 7) or (4, 6).

For the second sample test case, BaoBao can do one of the following three operations: (1, 1), (2, 2) or (3, 3).

题目大意:

给你两个串s1和s2,可以翻转s1串的一个区间,只能翻转一次,,问有多少对l,r使得翻转后的s1串等于s2串

解题报告:

当两串完全相同的时候就是马拉车,不同的时候就先两边往里扫到两串第一个不相同的位置,在第一个串往外扩,看能扩几次,答案就是多少。

注意无数细节,,,那个初始化(见注释)还有那个while(1)里面必须是if(l>=ed)就可以break了一开始写成了l>ed,,,WA了一上午难受难受。。。

其实不是细节多,,而是代码姿势不太对,,,还是太菜,,不过这么简单的一题比赛的时候没有开有点小亏。做网络同步赛打了三小时比赛水了7题,就去准备晚上给学弟讲课的PPT去了。。。这成绩对比了下,好像7题放现场赛也只是个铜(不过罚时较少可能是银?)。。不过这题是真不难。。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 4e6 + 5;
char s1[MAX],s2[MAX],str[MAX<<1];
int p[MAX<<1],top;
int manacher() {if(top == 0) return 0 ;int maxx = -1;int c = -1,r = -1;for(int i = 1; i<top; i++) {p[i] = r>i ? min(p[2*c-i],r-i) : 1;for(;str[i-p[i]] == str[i+p[i]];p[i]++);if(i+p[i] > r) {r = i+p[i];c=i;}maxx = max(maxx,p[i]);}return maxx-1;
}int main()
{int t;cin>>t;while(t--) {scanf("%s%s",s1,s2);int len = strlen(s1);if(strcmp(s1,s2) != 0) {int st=-1,ed=len,l,r;//需要赋初值!!! int flag = 1;for(int i = 0; i<len; i++) {if(s1[i] == s2[i]) st = i;else break;}for(int i = len-1; i>=0; i--) {if(s1[i] == s2[i]) ed = i;else break;}l=st+1,r=ed-1;while(1) {if(l >= ed) break;if(s1[l] == s2[r]) l++,r--;else {flag = 0;break;    }}if(flag == 0) {puts("0");continue;        }l=st,r=ed; while(1) {if(l==-1||r==len) break;if(s1[l] == s1[r]) l--,r++;else break;          }printf("%d\n",st-l+1);      continue;}top=0;str[top++] = '@';for(int i = 0; i<len; i++) {str[top++] = '#';str[top++] = s1[i];}str[top++] = '#';str[top] = '\0';manacher();ll ans = 0;for(int i = 2; i<top; i++) { ans += p[i]/2;              }printf("%lld\n",ans);}return 0 ;
}
//@#a#a#a#
//@#a#a#

【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维)相关推荐

  1. 2019 浙江省赛部分题解(The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)

    签到题 GLucky 7 in the Pocket Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao loves number 7 bu ...

  2. 【2019浙江省赛 - A】Vertices in the Pocket(权值线段树下二分,图,思维)

    题干: DreamGrid has just found an undirected simple graph with  vertices and no edges (that's to say, ...

  3. 【2019浙江省赛 - E】Sequence in the Pocket(思维)

    题干: DreamGrid has just found an integer sequence  in his right pocket. As DreamGrid is bored, he dec ...

  4. 【2019浙江省赛 - B】Element Swapping(思维,数学)

    题干: DreamGrid has an integer sequence  and he likes it very much. Unfortunately, his naughty roommat ...

  5. 【2019浙江省赛 - J】Welcome Party(并查集,bfs,优先队列,建图)

    题干: The 44th World Finals of the International Collegiate Programming Contest (ICPC 2020) will be he ...

  6. 19浙江省赛(回文串处理)

    K - Strings in the Pocket Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & ...

  7. java 分班_J 分班(class)(NYIST 2019年校赛)

    J 分班(class)(NYIST 2019年校赛) 内存限制:256MB 时间限制:1s Special Judge: No 题目描述: jsb 是 XX 市第一中学的校长.一轮模拟考试结束后,js ...

  8. 2019电赛总结(序)

    2019电赛总结(序) 文章目录 2019电赛总结(序) 1 序 2 嵌入式与单片机省赛落败 3 电赛启航 4 PID简述 5 那之后 电赛的一些经验 1 序 鄙人于某工大集成电路设计专业就学,但电子 ...

  9. WHU校赛2019(网络赛) 解题报告(CCNU_你们好强啊我们都是面包手) Apare_xzc

    WHU校赛2019(网络赛) 解题报告 CCNU_你们好强啊我们都是面包手(xzc zx lj) 战况: 比赛时3题,排名57,现在5题了 题目链接: WHU校赛2019 <-戳这里 以下题目按 ...

最新文章

  1. SQL Server物化视图学习笔记
  2. Apache服务器学习笔记
  3. 利剑无意之JAVA面试题(一)
  4. linux内核3.6版本及以下的bug引发的故障--cpu使用率100%
  5. 用gis打开tif格式_如何下载SHP矢量格式的等高线
  6. django web 自定义通用权限控制
  7. 【物理总结】初中物理重要常数、单位换算、概念、规律和理论及知识的应用归纳大全梳理总结
  8. JavaScript验证正则表达式大全
  9. java构造器 权限_一文搞懂Java的 构造方法 和 访问权限
  10. Python数据结构与算法(4.1)——递归
  11. PHP导出MySQL数据到Excel文件
  12. 【系统集成项目管理工程师】—计算真题公式汇总及分析
  13. 读书笔记_算法第四版(一)
  14. 开源中国众包平台 —— 为什么我们需要托管赏金
  15. glibc源码下载在线阅读地址
  16. 重写Readable接口read()方法 传入Scanner导致的BufferOverflowException报错
  17. 口渴·冰绿茶心情 -旧文
  18. RFID资产管理|超高频RFID技术在医院资产管理项目中的应用-铨顺宏
  19. 【输出一个静态“心形”图案、一个跳动的“心”——使用C++、C语言来实现】
  20. js判断ipad pro设备

热门文章

  1. 从零开始学习jQuery (三) 管理jQuery包装集【转】
  2. 第六章 参数估计(续)
  3. codeUp 2031 To fill or not to fill 复杂贪心
  4. python将excel日期比大小_sql与excel、python比较(二)——日期和时间函数
  5. 修改小程序swiper 点的样式_高质量的微信小程序样式模板应该长什么样?
  6. ubantu 添加防火墙策略_Ubuntu 14.04 配置iptables防火墙
  7. mysql100个优化技巧_完整篇:100+个MySQL调试和优化技巧(2)
  8. B. File List
  9. n型半导体和p型半导体的区别_VNX系列大流量工业型膜堆, 为半导体等行业提供超纯水!...
  10. 当c语言表达式中同时有字符 整数,c语言第2章数据类型、运算符与表达式a.ppt