hdu 4662 MU Puzzle

题目链接: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

2013 Multi-University Training Contest 6

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,布布扣,bubuko.com

时间: 2024-08-02 10:57:39

hdu 4662 MU Puzzle的相关文章

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.

HDU 4021 24 Puzzle (拼图)

24 Puzzle Problem Description Daniel likes to play a special board game, called 24 puzzle. 24 puzzle is such a game that there are tiles with the number 1 to 23 in a play board like the follow picture: The '#' denotes the positions that the tiles may

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

HDU 1538 A Puzzle for Pirates (海盗分金问题)

A Puzzle for Pirates Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 508    Accepted Submission(s): 167 Problem Description A bunch of pirates have gotten their hands on a hoard of gold pieces a

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<algori

人生第一个快速幂的题(HDU - 1097--A hard puzzle )

题意: 最简单的快速幂.给你两个数n和m,求n^m的最后一位: 解题思路: 额,快速幂就很简单了,这里只要最后一位可以一对每次运算都%10: 代码: #include<cstdio> #include<cstring> #include<algorithm> #include <iostream> using namespace std; #define N 100000 long long n,m; long long pow_(long long n,l

HDU 1538 A Puzzle for Pirates 经典海盗分金币

题目:这是一个经典问题,有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续. 首先我们讲一下海盗分金决策的三个标准:保命,拿更多的金子,杀人,优先级是递减的. 同时分为两个状态稳定状态和不稳定状态:如果当n和m的组合使得最先决策的人(编号为n)不会被丢下海, 即游戏会立即结束, 就称这个状态时"稳定的". 反之, 问题会退化为n-1和m的组合, 直到达到一个稳定状态, 所以乘

HDU 2931 Digit Puzzle 搜索 DFS

#include<cstdio> #include<cstring> int num[3],tot,n,f; char s[3][100],ans[3][100]; int check() { char str[100]; int a=0,b=0,c; for(int i=0;i<num[0];i++) a=a*10+s[0][i]-'0'; for(int i=0;i<num[1];i++) b=b*10+s[1][i]-'0'; c=a*b; for(int i=n

【练习——逆序对】N*M Puzzle / Simple Puzzle

HDU P3600 Simple Puzzle POJ P2893 N*M Puzzle (咕在前面, 这是两道基本一样的题, 我都没有A掉, 但我觉得我写的十分正确!!!不想改了先放上来orz 思路:这个题真是妙啊qwq我特意新建了一个“妙啊”分类给它qwq(然而A不掉 将二维转化为一维, 从左往右从上至下, 遇到0(空格)跳之~ 可知空格左右移动对一维序列无影响, 上下移动会向前或向后移动, 跳过(m-1)个格子//这里n行m列 如果列数为奇数, (m-1)为偶数, 则无论移动的数与跳过的数