题意: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的不可以,其他都可以
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x3f3f3f3f; 11 const double eps=1e-5; 12 typedef long long ll; 13 #define cl(a) memset(a,0,sizeof(a)) 14 #define ts printf("***** "); 15 const int MAXN=1005055; 16 int n,m,tt; 17 char s[MAXN]; 18 int main() 19 { 20 int i,j,k; 21 #ifndef ONLINE_JUDGE 22 freopen("1.in","r",stdin); 23 #endif 24 scanf("%d",&tt); 25 while(tt--) 26 { 27 scanf("%s",s); 28 if(s[0]!='M') 29 { 30 printf("No "); 31 continue; 32 } 33 int cnt=0; 34 bool flag=1; 35 int len=strlen(s); 36 for(i=1;i<len;i++) 37 { 38 if(s[i]=='M') 39 { 40 flag=0; 41 break; 42 } 43 if(s[i]=='I') cnt++; 44 else cnt+=3; 45 } 46 if(((cnt%6==0)||cnt%2==1&&cnt!=1)||!flag) 47 { 48 printf("No "); 49 } 50 else 51 printf("Yes "); 52 } 53 }