题意:Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols called "words". We start with one word MI, and transform it to get a new word. In each step, we can use one of the following transformation rules:
1. Double any string after the M (that is, change Mx, to Mxx). For example: MIU to MIUIU.
2. Replace any III with a U. For example: MUIIIU to MUUU.
3. Remove any UU. For example: MUUU to MU.
Using these three rules is it possible to change MI into a given string in a finite number of steps?
首先全部转化为I
可以发现,能被6整除或者i的个数是奇数且不为1的不可以,其他都可以
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
char s[MAXN];
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
scanf("%s",s);
if(s[]!='M')
{
printf("No\n");
continue;
}
int cnt=;
bool flag=;
int len=strlen(s);
for(i=;i<len;i++)
{
if(s[i]=='M')
{
flag=;
break;
}
if(s[i]=='I') cnt++;
else cnt+=;
}
if(((cnt%==)||cnt%==&&cnt!=)||!flag)
{
printf("No\n");
}
else
printf("Yes\n");
}
}