MU puzzle

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;
}
时间: 2024-12-29 09:19:17

MU puzzle的相关文章

hdu 4662 MU Puzzle

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 MU PuzzleTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1296    Accepted Submission(s): 539 Problem Description Suppose there are the symbols

HDU 4662 MU Puzzle:找规律

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻倍.For example: MIU to MIUIU. (2)将'III'变为一个'U'.For example: MUIIIU to MUUU. (3)删除'UU'.For example: MUUU to MU 给你一个字符串s,问你是否能将初始字符串"MI"通过一系列操作变为s.

MU Puzzle HDU - 4662

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. D

ZOJ 3435 Ideal Puzzle Bobble

ZOJ Problem Set - 3435 Ideal Puzzle Bobble Time Limit: 2 Seconds      Memory Limit: 65536 KB Have you ever played Puzzle Bobble, a very famous PC game? In this game, as a very cute bobble dragon, you must keep shooting powerful bubbles to crush all t

UVa - 227 - Puzzle

给空格子上下左右的互换操作,问最后是怎样的 注意一行的最后一个若是空格,需要自己加注意读取时 操作可能分好多行,一定要读取到 0 为止 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char map[50][50],op[1000],c,tmp; 5 int k,t,x,y,cnt; 6 bool flag; 7 void fuc() 8 { 9 flag=1; 10 for(int i=0;

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

Dearboy&#39;s Puzzle (poj 2308 搜索 dfs+bfs)

Language: Default Dearboy's Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1202   Accepted: 208 Description Dearboy is a game lover. Recently, he loves playing the game Lian Lian Kan. This game is played on a board with N*M grids