码迷,mamicode.com
首页 > 其他好文 > 详细

MU puzzle

时间:2017-08-06 22:00:26      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:mui   string   str   通过   har   class   span   ring   strlen   

2017-08-06 20:49:38

writer:pprp

三种操作:

  1、MUI -> MUIUI

  2、MUUU -> MU

  3、MUIII -> MUU

分析:有两个操作:将所有的U都换成I对I的个数进行判断;

    1的操作是将这个个数乘以2

    2/3操作综合起来相当于可以-6

于是可以计算出来I的个数,判断能否通过*2或者-6的操作将其变成1

代码如下;

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN = 1e6 + 10 ;

char str[MAXN];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",str);
        if(str[0]!=M)
        {
            puts("No");
            continue;
        }
        int len = strlen(str);
        int ok =1;
        int num = 0;
        for(int i = 1;i<len;i++)
            if(str[i]==I)
                num ++ ;
            else if(str[i]==U)
                num += 3;
            else if(str[i]==M)
            {
                ok = 0;
                break;
            }
        if(!ok)
        {
            puts("No");
            continue;
        }
        if(num==1)
        {
            puts("Yes");
            continue;
        }
        ok = 0;
        int t =num%6;
        if(t==2 || t==4)
            ok=1;
        if(ok) puts("Yes");
        else puts("No");
    }
    return 0;
}

 

MU puzzle

标签:mui   string   str   通过   har   class   span   ring   strlen   

原文地址:http://www.cnblogs.com/ilovelianghui/p/7295970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!