Codeforces Round #442 (Div. 2) B. Nikita and string
題意:給一個字符串,問形如a……a/ /b……b/ /a……a的子串最大長度
題解:設三個狀態a,ab,aba分別表示對應長度。因為每段長度可以為0,所以後一個狀態的包含前一個狀態。每次更新最大長度,最終的aba即為答案
1 #include <bits/stdc++.h> 2 using namespace std; 3 char str[5050]; 4 int main() 5 { 6 cin>>str; 7 int len=strlen(str); 8 int a,ab,aba; 9 a=ab=aba=0; 10 for(int i=0;i<len;i++) 11 { 12 if(str[i]==‘a‘) 13 a++,aba++; 14 else 15 ab++; 16 ab=max(a,ab); 17 aba=max(ab,aba); 18 } 19 cout<<aba<<endl; 20 }
Codeforces Round #442 (Div. 2) B. Nikita and string
相關推薦
Codeforces Round #442 (Div. 2) B. Nikita and string
style force c++ its class char 每次 包含 子串 題意:給一個字符串,問形如a……a/ /b……b/ /a……a的子串最大長度 題解:設三個狀態a,ab,aba分別表示對應長度。因為每段長度可以為0,所以後一個狀態的包含前一個狀態。每次更新
Codeforces Round #442 (Div. 2) 877E - Danil and a Part-time Job dfs序+線段樹
pac upd style init problem def ios const clas Codeforces Round #442 (Div. 2) 877E - Danil and a Part-time Job emmmm第一次見的東西感覺都好神奇 #inclu
Codeforces Round #267 (Div. 2) B. Fedor and New Game【位運算/給你m+1個數讓你判斷所給數的二進制形式與第m+1個數不相同的位數是不是小於等於k,是的話就累計起來】
ons ecif 否則 ans contain rst rmi sum any After you had helped George and Alex to move in the dorm, they went to help their friend
Codeforces Round #524 (Div. 2) B. Margarite and the best present 規律題
B. Margarite and the best present time limit per test 1 second memory limit per test 256 megabytes input standard input output stand
Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 題目連結:https://codeforc.es/contest/1088/problem/B 題意: 給出n個數,給出k次操作,然後每次操作把所有數減去最小值,輸出這個最小值,k用不完用0來補。 題解: 考慮到重複的數會被一起減去,所以我用了個set
Codeforces Round #525 (Div. 2) B. Ehab and subtraction
題解 題目大意 給一個數列n 每次將其中最小的元素取出並輸出 整個序列非0元素全部減去這個最小元素往復操作k次 將陣列排序併除重 因為如果元素相同肯定減去之後另一個為0 記錄一個減去的量每次取出最小的 輸出值-減去量 AC程式碼 #include <stdio.h>
想法題——Codeforces Round #190 (Div. 2)——B. Ciel and Flowers
B. Ciel and Flowers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard out
Codeforces Round #533 (Div. 2) B. Zuhair and Strings 【模擬】
組成 each limit names erl least pbo c++ ram 傳送門:http://codeforces.com/contest/1105/problem/B B. Zuhair and Strings time limit per test 1
Codeforces Round #419 (Div. 2) B. Karen and Coffee 預處理+技巧
Note In the first test case, Karen knows 3 recipes. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. The second one r
Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field
Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in eac
Codeforces Round #291 (Div. 2) B. Han Solo and Lazer Gun
reg abs ins getchar stream 直線 name stdout etc 因為是x,y均為整數因此對於同一直線的點,其最簡分數x/y是相同的(y可以為0,這裏不做除法)於是將這些點不斷求最簡分數用pair在set中去重即可。 #include <
【題解】codeforces1058B[Codeforces Round #512 Div.2 B]B.Vasya and Cornfield 數學知識
Description Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle wi
Codeforces Round #294 (Div. 2) E. A and B and Lecture Rooms(lca+思維,樹上尋找與給定兩個點距離相等的點的個數)
E. A and B and Lecture Rooms time limit per test 2 seconds memory limit per test 256 megabytes input standard input output
Codeforces Round #263 (Div.1) B. Appleman and Tree
ace apple n+1 test right art [0 pan target 題目地址:http://codeforces.com/contest/461/problem/B 題目大意:給一棵樹。每一個點為白色或黑色。切斷一些邊,使得每一個連通塊有且僅有一個黑點
Codeforces Round #365 (Div. 2) D - Mishka and Interesting sum(離線樹狀數組)
turn string 之前 algorithm printf ace r++ void contest http://codeforces.com/contest/703/problem/D 題意: 給出一行數,有m次查詢,每次查詢輸出區間內出現次數為偶數次的數字的異
【動態規劃】 Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
and main spa def esp 動態 return 價值 can 劃分那個序列,沒必要完全覆蓋原序列。對於劃分出來的每個序列,對於某個值v,要麽全都在該序列,要麽全都不在該序列。 一個序列的價值是所有不同的值的異或和。整個的價值是所有劃分出來的序列的價值之和。
【分類討論】【spfa】【BFS】Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game
邊界情況 code def bfs spa eof scan string amp 那個人第一步肯定要麽能向下走,要麽能向右走。於是一定可以判斷出上下是否對調,或者左右是否對調。 然後他往這個方向再走一走就能發現一定可以再往旁邊走,此時就可以判斷出另一個方向是否對調。 都判
[Codeforces Round #261 (Div. 2) E]Pashmak and Graph(Dp)
solution and other main ems scanf homework max urn Description Pashmak‘s homework is a problem about graphs. Although he always tries
Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模擬 枚舉
ces color 一次 name exit main cst space amp Codeforces Round #417 (Div. 2) A. Sagheer and Crossroads 模擬 枚舉 題意 一個紅綠燈 按逆時針方向一次給出各個路口的左轉,
(博弈sg) Codeforces Round #417 (Div. 2) E Sagheer and Apple Tree
paths 相同 friend pri 產生 chan star ren have Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered