您的位置:首页 > 其它

hdu 4622 **

2015-07-04 23:27 204 查看
题意: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-5;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=1005055;
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[0]!='M')
{
printf("No\n");
continue;
}
int cnt=0;
bool flag=1;
int len=strlen(s);
for(i=1;i<len;i++)
{
if(s[i]=='M')
{
flag=0;
break;
}
if(s[i]=='I')   cnt++;
else cnt+=3;
}
if(((cnt%6==0)||cnt%2==1&&cnt!=1)||!flag)
{
printf("No\n");
}
else
printf("Yes\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: