思路讲解
1 2 3 4 5 6 7
| if(S[1]=='s'){ S[1]='.'; } if(S[N]=='p'){ S[N]='.'; }
|
然后就是不能有p出现在s之后,不能有s出现在p之后,非常简单吧
AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #include <iostream> #include <cstring> #include <algorithm> #include <deque> #include <queue> #include <vector> #include <set> #include <map> #include <cmath> #include <bitset> #include <iterator> #include <random> #include <iomanip> #include <cctype> #include <array>
typedef long long ll; const ll MAXN=510; ll N,T; char S[MAXN];
void solve(){ std::cin>>N; for(int i=1;i<=N;++i){ std::cin>>S[i]; } if(S[1]=='s'){ S[1]='.'; } if(S[N]=='p'){ S[N]='.'; } for(int i=1;i<=N-1;++i){ if(S[i]=='p'){ for(int j=i+1;j<=N;++j){ if(S[j]=='s'){ std::cout<<"NO\n"; return; } } } if(S[i]=='s'){ for(int j=i+1;j<=N;++j){ if(S[j]=='p'){ std::cout<<"NO\n"; return; } } } } std::cout<<"YES\n"; return; }
int main() { std::ios::sync_with_stdio(false); std::cin.tie(0);std::cout.tie(0); std::cin>>T; while (T--) { solve(); } return 0; }
|
心路历程(WA,TLE,MLE……)