题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662

MU Puzzle

Time 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 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?
 
Input
First line, number of strings, n. 

Following n lines, each line contains a nonempty string which consists only of letters 'M', 'I' and 'U'. 



Total length of all strings <= 106.
 
Output
n lines, each line is 'Yes' or 'No'.
 
Sample Input
2
MI
MU
 
Sample Output
Yes
No
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:  4822 4821 4820 4819 4818 
 

规律题,把u所有化成i,然后多写下,就能发现规律

#include<iostream>
#include<cstring>
using namespace std;
char str[1000010];
int main()
{
int n;
cin>>n;
while(n--)
{
cin>>str;
int l=strlen(str),xi=0,xu=0,k=0;
if(str[0]!='M')
{
cout<<"No"<<endl;
continue;
}
for(int i=1;i<l;i++)
{
if(str[i]=='I')
xi++;
else if(str[i]=='U')
xu++;
else
{
k=1;
break;
}
}
if(k==1 || ((xi+xu)%2==1 && !(xi==1 && xu==0)) || xi%3==0)
{
cout<<"No"<<endl;
continue;
}
else
{
cout<<"Yes"<<endl;
continue;
}
}
return 0;
}

hdu 4662 MU Puzzle的更多相关文章

  1. HDU 4662 MU Puzzle (2013多校6 1008 水题)

    MU Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 4662 MU Puzzle:找规律

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻 ...

  3. HDU 4662 MU Puzzle 数论或者水题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4662 题目是问目标串能否由MI得到,我们可以逆向思维,目标串能否反过来处理得到MI,所以,首先排除M ...

  4. 【找规律】HDU 4662——MU Puzzle

    来源:点击打开链接 这个题目的来源是人工智能领域MU猜想.比赛的时候也参考了相关资料,可是最后差一点没有把规律推出来. 注意到以下几个性质.第一,MI怎么变换M永远只能在第一位.第二,因为变换时只能在 ...

  5. HDU 4662 MU Puzzle(找规律)

    题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去 ...

  6. HDU 4662 MU Puzzle 简单找规律

    没有任何变换(III变U和删UU操作)之前,I 的个数一定是2^x个(也就是2的整数次幂) 若仅考虑III变U,那么设U的个数为k,I 的个数变为2^x-3*k 再加上删除UU操作,假设我们删除了2* ...

  7. HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6

    现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...

  8. MU Puzzle HDU - 4662

    Suppose there are the symbols M, I, and U which can be combined to produce strings of symbols called ...

  9. HDU-4662 MU Puzzle 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 倒推考虑长度就可以了. //STATUS:C++_AC_31MS_240KB #include ...

随机推荐

  1. LeetCode: Unique Paths I & II & Minimum Path Sum

    Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m  ...

  2. poj 2773 Happy 2006

    // 题意 :给你两个数 m(10^6),k(10^8) 求第k个和m互质的数是什么这题主要需要知道这样的结论gcd(x,n)=1 <==> gcd(x+n,n)=1证明 假设 gcd(x ...

  3. poj 1392 Ouroboros Snake

    题目描述:咬尾蛇是古埃及神话中一种虚构的蛇.它经常把尾巴放在自己的嘴巴里,不停地吞噬自己.环数类似于咬尾蛇,它是2^n位的二进制数,具有如下性质:它能“生成”0-2^n-1之间的所有数.生成方法是:给 ...

  4. asp.net MVC 应用程序的生命周期(上)

    首先我们知道http是一种无状态的请求,他的生命周期就是从客户端浏览器发出请求开始,到得到响应结束.那么MVC应用程序从发出请求到获得响应,都做了些什么呢? 本文我们会详细讨论MVC应用程序一个请求的 ...

  5. HDU 5742 It's All In The Mind

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  6. CXF之一 基础理论介绍

    WebService介绍   WebService让一个程序可以透明地调用互联网程序,不用管具体的实现细节.只要WebService公开了服务接口,远程客户端就可以调用服务.WebService是基于 ...

  7. User Agent

    Android: Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; MI-ONE Plus Build/GINGERBREAD) AppleWebKit/533 ...

  8. 【原】Storm Tutorial

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  9. (转载)OC学习篇之---概述

    前言 终于开启了OC的学习篇了,之前由于工作上的事,学习就一直搁浅了,不过最近由于各种原因,感觉必须要开启iOS的开发旅程了,不然就老了.因为之前一直是做Android的,所以学习iOS来就没那么费劲 ...

  10. web.py处理文件上传

    #coding=utf8 import web urls = ('/','Home', '/upload', 'Upload') app = web.application(urls, globals ...