HDU 4662 MU Puzzle (2013多校6 1008 水题)
MU Puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 134 Accepted Submission(s): 71
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?
Following n lines, each line contains a nonempty string which consists only of letters 'M', 'I' and 'U'.
Total length of all strings <= 106.
MI
MU
No
/*
* 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 水题)的更多相关文章
- HDU 4639 Hehe (2013多校4 1008 水题)
Hehe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6
现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...
- hdu 4662 MU Puzzle
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 MU Puzzle Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4662 MU Puzzle:找规律
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4662 题意: 初始字符串为"MI". 有三个操作: (1)将'M'之后的所有字符翻 ...
- HDU 4662 MU Puzzle 数论或者水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4662 题目是问目标串能否由MI得到,我们可以逆向思维,目标串能否反过来处理得到MI,所以,首先排除M ...
- 【找规律】HDU 4662——MU Puzzle
来源:点击打开链接 这个题目的来源是人工智能领域MU猜想.比赛的时候也参考了相关资料,可是最后差一点没有把规律推出来. 注意到以下几个性质.第一,MI怎么变换M永远只能在第一位.第二,因为变换时只能在 ...
- HDU 4662 MU Puzzle(找规律)
题意:问是否能把MI通过以下规则转换成给定的字符串s. 1.使M之后的任何字符串加倍(即,将Mx更改为Mxx). 例如:MIU到MIUIU.2.用U替换任何III.例如:MUIIIU至MUUU.3.去 ...
- HDU 4662 MU Puzzle 简单找规律
没有任何变换(III变U和删UU操作)之前,I 的个数一定是2^x个(也就是2的整数次幂) 若仅考虑III变U,那么设U的个数为k,I 的个数变为2^x-3*k 再加上删除UU操作,假设我们删除了2* ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
随机推荐
- gpio子系统和pinctrl子系统(下)
情景分析 打算从两个角度来情景分析,先从bsp驱动工程师的角度,然后是驱动工程师的角度,下面以三星s3c6410 Pinctrl-samsung.c为例看看pinctrl输入参数的初始化过程(最开始的 ...
- charger related source code position
Platform Qualcomm MSM8917 or MSM8937 Source kernel/msm-3.18/drivers/power/qpnp-smbcharger.c kernel/m ...
- redis线程安全性
总体来说快速的原因如下: 1)绝大部分请求是纯粹的内存操作(非常快速) 2)采用单线程,避免了不必要的上下文切换和竞争条件 3)非阻塞IO 内部实现采用epoll,采用了epoll+自己实现的简单的事 ...
- Author name disambiguation using a graph model with node splitting and merging based on bibliographic information
Author name disambiguation using a graph model with node splitting and merging based on bibliographi ...
- POJ 1160 Post Office(DP+经典预处理)
题目链接:http://poj.org/problem?id=1160 题目大意:在v个村庄中建立p个邮局,求所有村庄到它最近的邮局的距离和,村庄在一条直线上,邮局建在村庄上. 解题思路:设dp[i] ...
- Python+Selenium 自动化实现实例-获取页面元素信息(百度首页)
#coding=utf-8from selenium import webdriverdriver = webdriver.Chrome()driver.get("http://www.ba ...
- MapReduce案例一:天气温度
1.需求 2.思路 3.代码实现 3.1MyWeather 类代码: 这个类主要是用来定义hadoop的配置,在执行计算程序时所需加载的一些类. package com.hadoop.mr.weath ...
- 数据库之存储过程(Stored Procedure)【未完待续】
存储过程(Stored Procedure,以下简称SP)是啥?有什么用?优缺点? 一个SP是一段存储在数据库系统中的一条或多条sql语句的集合,类似一条批处理,它能被触发器,或者其他的SP以及APP ...
- AC日记——Sagheer and Nubian Market codeforces 812c
C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...
- Template Mode 'HTML5' is deprecated与UnsatisfiedDependencyException
org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode 'HTML5' is deprecated. Usi ...