日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019浙江省赛 - K 】Strings in the Pocket(马拉车,思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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(马拉车,思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲精品人 | 香蕉视频911| 人人妻人人爽一区二区三区 | 国产天天骚| 亚洲精品a| 亚洲另类xxxx | 成人在线免费网站 | 成人欧美一级特黄 | 国产成人精品无码免费看在线 | 欧美亚洲在线 | 熟女视频一区 | 两个人做羞羞的视频 | 亚洲第一二三四区 | 亚洲一区二区三区久久 | 全程偷拍露脸中年夫妇 | 热久久在线| 欧美7777 | 妺妺窝人体色www在线小说 | 波多野结衣一区二区 | 国产xxxxx视频 | 亚洲依依 | 日本视频免费在线 | 日韩手机在线视频 | 中文精品无码中文字幕无码专区 | 国模私拍xvideos私拍 | 狼性av| 国产黄色片免费观看 | 福利在线看 | yjizz视频 | 欧美三级a | 免费婷婷 | 极度诱惑香港电影完整 | 日本伦理片在线看 | 3d成人动漫在线观看 | 5566毛片 | 国产美女一区二区三区 | 好吊色欧美一区二区三区视频 | 日韩在线视频中文字幕 | 秋霞欧洲| 极品色影视 | 中文天堂在线资源 | 人妖videosex高潮另类 | 草草草在线 | 69人妻一区二区三区 | 黄色片视频| 久久久久久久久免费 | 丁香花电影免费播放在线观看 | 打屁股疼的撕心裂肺的视频 | 欧美黄色大片免费观看 | 日韩av毛片在线观看 | 日韩三级视频在线播放 | 国产91成人 | 91少妇丨porny丨 | 午夜天堂精品久久久久 | 亚州男人天堂 | 国产精品无码久久久久久电影 | 久久免费黄色网址 | 第一av| 打开免费观看视频在线 | 久久黄色大片 | 色婷婷狠狠18禁久久 | 全黄一级裸体片 | 日本久久激情 | 欧美性一级 | 亚洲国产不卡 | 麻豆天天躁天天揉揉av | 久久精品国产网红主播 | 日韩一区二区在线免费观看 | 超碰97在线看 | 久久久精品电影 | 国产新婚疯狂做爰视频 | 欧美精品一区在线发布 | 韩国三级hd中文字幕的背景音乐 | 初尝黑人巨炮波多野结衣 | 日韩高清影视在线观看 | 香蕉久久精品日日躁夜夜躁 | 国产午夜视频在线观看 | 国产不卡一区二区视频 | jizz国产精品 | 色偷偷网| av片子在线观看 | 国产精品1234 | 欧美xo影院 | 99无码熟妇丰满人妻啪啪 | 欧美日韩色图 | 中文字幕亚洲乱码熟女一区二区 | 美女爱爱爱| 日韩免费一区二区三区 | 毛片入口| 免费中文字幕日韩 | 中文字幕在线视频观看 | 少妇一级片| 免费观看国产视频 | 中文字幕av不卡 | √天堂8资源中文在线 | 少妇99| 特级西西人体444www | 我们俩电影网mp4动漫官网 | 那里可以看毛片 |