C++,codeforces,1873A, A. Short Sort /* codeforces,1873A, A. Short Sort 判断一个由a,b,c组成的字符串是否是可以通过对字符串"abc"进行1次或0次交换字符操作得到 交换字符操作是指,将字符串中的两个字符交换位置 */ /* 符号条件的字符串一定有一个位置的字符与"abc"相同,即 abc,acb abc,cba abc,...
A. Short Sort 【交换】 描述:对一个字符串“acb”/“bac”……选择任意两个字符做交换,若最后能得到“abc”就输出YES。 解: 特解:因为只交换两个,剩下那一个就必须在原位置。 strings;cin>>s;if(s[0]=='a '||s[1]=='b '||s[2]=='c')YY;elseNN; 通解:如果要模拟交换,就会有Cn2=n(n...
Short Sort * Contest: Codeforces - Codeforces Round 898 (Div. 4) * URL: https://codeforces.com/contest/1873/problem/A * MemoryL: 256 MB * TimeL: 1000 ms * === */ #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false),cin.tie(nullptr)...
there should be at least one node in both part, i.e. there should exist i such that x[0][i] = 'O'. And then we can check if for all i,j: x[i][j] = (i-th node and j-th node in the same part ? 'E' : 'O'), if not, there is no solution. Otherwise we can buil...
Solution:Simply run the automaton. SuffixAutomatona(s);boolfail=false;intn=0;for(inti=0;i<w.size();i++){if(a.edges[n].find(w[i])==a.edges[n].end()){fail=true;break;}n=a.edges[n][w[i]];}if(!fail)cout<<w<<" is a substring of "<<s<<"\n"; ...
We know that if there's a solution, then the heights from the min. to max. height are non-decreasing on each side. If there's another solution, we can sort the foxes on each side between the min. and max. height without worsening the max. difference. ...