MU Puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 134    Accepted Submission(s): 71

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
 
 
 
 
 
全场最水的题目。
 
 
一开始时MI。
其实可以全部转化成I的个数。
 
一个U相当于3个I,减少两个U,相当于减少6个I。
 
第一个操作相当于可以把I的个数翻倍。
 
 
所以1个I,2个I,4个I,8,16,32,。。。。这些2^n个I都是可以实现的。
 
 
而且可以减掉6个I,8-6=2,16-6=10,10-6=4,等等都可以。
 
10个I可以,20个I也可以。
 
 
这样数I的个数,比赛时候暴力预处理下所以可以的情况,就像晒素数一样。
 
 
 
其实可以发现规律的,除了一个I之外,奇数个I和个数被6整除的都不行,可以根据整除性分析下。
 
 
 
 
 
 
 
贴上代码,里面有一个init函数式预处理的,虽然没有用上
 
 
 
 /*
* Author: kuangbin
* Created Time: 2013/8/8 11:54:08
* File Name: 1008.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
using namespace std;
char str[];
const int MAXN = ;
bool dp[MAXN];
bool vis[MAXN];
void init()
{
memset(dp,false,sizeof(dp));
memset(vis,false,sizeof(vis));
dp[] = true;
queue<int>q;
q.push();
vis[] = true;
while(!q.empty())
{
int tmp = q.front();
dp[tmp] = true;
q.pop();
if(tmp == ){dp[] = true;vis[] = true;continue;}
if(tmp >= && !vis[tmp-])
{
q.push(tmp-);
vis[tmp-] = true;
}
tmp *= ;
while(tmp < MAXN)
{
if(vis[tmp])break;
dp[tmp] = true;
if(tmp >= && !vis[tmp-])
{
q.push(tmp-);
vis[tmp-] = true;
}
tmp *= ;
}
}
} int main()
{
int T;
init();
scanf("%d",&T);
while(T--)
{
bool flag = true;
scanf("%s",str);
int len = strlen(str);
if(str[]!='M')
{
printf("No\n");
continue;
}
int cnt = ;
for(int i = ;i < len;i++)
{
if(str[i]=='M')
{
flag = false;
break;
}
if(str[i] =='I')cnt++;
else cnt+= ;
}
if(!flag)
{
printf("No\n");
continue;
}
if(cnt == )
{
printf("Yes\n");
continue;
}
if(cnt% == || cnt% == )printf("No\n");
else printf("Yes\n");
}
return ;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

HDU 4662 MU Puzzle (2013多校6 1008 水题)的更多相关文章

  1. HDU 4639 Hehe (2013多校4 1008 水题)

    Hehe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

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

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

  3. hdu 4662 MU Puzzle

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 MU Puzzle Time Limit: 2000/1000 MS (Java/Others) ...

  4. HDU 4662 MU Puzzle:找规律

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

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

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

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

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

  7. HDU 4662 MU Puzzle(找规律)

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

  8. HDU 4662 MU Puzzle 简单找规律

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

  9. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

随机推荐

  1. FC4-i386-SRPMS

    [重点] http://archives.fedoraproject.org/pub/archive/fedora/linux/core/6/ http://archives.fedoraprojec ...

  2. [hadoop][基本原理]zookeeper场景使用

    代码:https://github.com/xufeng79x/ZkClientTest 1. 简介 zookeeper的特性决定他适用到某些场景非常合适,比如典型的应用场景: 1.集群管理(Grou ...

  3. form表单 datalist 和legend

    <form action="" method="post" > <fieldset> <legend> 表单元素 </ ...

  4. jQuery 中的 unbind() 方法

    jQuery 中的 unbind() 方法是 bind() 方法的反向操作,从每一个匹配的元素中删除绑定的事件. 语法结构: unbind([type][, data]); type是事件类型,dat ...

  5. 使用 Visual Studio 部署 .NET Core 应用

    可将 .NET Core 应用程序部署为依赖框架的部署或独立部署,前者包含应用程序二进制文件,但依赖目标系统上存在的 .NET Core,而后者同时包含应用程序和 .NET Core 二进制文件. 有 ...

  6. C# Merge into的使用详解

    Merge是一个非常有用的功能,类似于Mysql里的insert into on duplicate key. Oracle在9i引入了merge命令, 通过这个merge你能够在一个SQL语句中对一 ...

  7. Factorial Trailing Zeroes——数学类

    Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...

  8. react native 调用Android原生方法

    来源:https://www.youtube.com/watch?v=WmJpHHmOKM8 教程:https://www.youtube.com/watch?v=GiUo88TGebs Breaki ...

  9. Structs2 校验框架

    代码结构: 使用Struts校验框架,保证输入学生的基本信息:学号.姓名.性别.出生年月.专业.总学分等,要求输入满足以下条件:(1) 学号前两位大于“13”并且后面4位必须为数字:(2) 出生年月必 ...

  10. 【SQL】oralce中使用group by和case when按照条件求和

    假设我们有一个Salary 薪水表.这个表的字段分别为:id, name, salary, level  在这个表中,每个人有不同的级别(level).我们要根据不同的级别统计相同级别员工的薪水总和. ...