思路:多写几组数据就可以找到规律了,就是要找到当前位置,往左往右的不完全连续L和R的最大长度
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #include <algorithm> #include <queue> using namespace std; queue<int>q; int main() { while(!q.empty()) q.pop(); int n; string s; cin>>n; cin>>s; for(int c=0;c<n;c++) { int i=c-1,j=c; int l=1,r=1; while(s[i]!='L'&&i>=0) if(s[i]=='R') l++,i--; else i--; while(s[j]!='R'&&j<n) if(s[j]=='L') r++,j++; else j++; q.push(max(r,l)); } while(q.size()!=1) { printf("%d ",q.front()); q.pop(); } printf("%d ",q.front()); return 0; }