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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【2019牛客暑期多校训练营(第八场)- G】Gemstones(栈,模拟)

發(fā)布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【2019牛客暑期多校训练营(第八场)- G】Gemstones(栈,模拟) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

鏈接:https://ac.nowcoder.com/acm/contest/888/G
來源:牛客網(wǎng)
?

Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.

?

After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the gemstone sequence each time, after taking away three gemstones, the left two parts of origin sequence will be merged to one sequence in origin order automatically.

?

For example, as for "ATCCCTTG", we can take three 'C's away with two parts "AT", "TTG" left, then the two parts will be merged to "ATTTG", and we can take three 'T's next time.

?

The password of this level is the maximum possible times to take gemstones from origin sequence.

?

Please help them to determine the maximum times.

輸入描述:

?

Only one line containing a string ss_{}s?, denoting the gemstone sequence, where the same letters are regarded as the same types.

?

?

1≤∣s∣≤1051 \le |s| \le 10^51≤∣s∣≤105

?

ss_{}s? only contains uppercase letters.

輸出描述:

Print a non-negative integer in a single line, denoting the maximum times.

示例1

輸入

復(fù)制

ATCCCTTG

輸出

復(fù)制

2

說明

One possible way is that ‘‘ATCCCTTG?"??→??‘‘ATTTG?"??→‘‘AG?"``ATCCCTTG\," \; \rightarrow \; ``ATTTG\," \; \rightarrow ``AG\,"‘‘ATCCCTTG"→‘‘ATTTG"→‘‘AG".

題目大意:

給一個字符串 3個連續(xù)且相同的能夠消去 問這個字符串最多消去幾次

解題報告:

棧模擬。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; char s[MAX]; char stk[MAX]; int top = 100,ans; int ok() {if(stk[top] == stk[top-1] && stk[top-1] == stk[top-2]) {top -= 3;return 1;}else return 0; } int main() {cin>>s+1;int len = strlen(s+1);for(int i = 1; i<=len; i++) {stk[++top] = s[i];ans += ok();}printf("%d\n",ans);return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【2019牛客暑期多校训练营(第八场)- G】Gemstones(栈,模拟)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。