zoukankan      html  css  js  c++  java
  • HDU 4662 MU Puzzle(找规律)

    题意:问是否能把MI通过以下规则转换成给定的字符串s。

    1.使M之后的任何字符串加倍(即,将Mx更改为Mxx)。 例如:MIU到MIUIU。
    2.用U替换任何III。例如:MUIIIU至MUUU。
    3.去掉任何UU。 例如:MUUU到MU。

    分析:

    1、MI的变换首先要复制I,可以复制为1,2,4,8,16,32,……(2的n次方)个。

    2、由于可以用U替换任何III,所以将字符串s中所有的U变为I后,统计I的个数cnt。

    3、由于可以去掉任何UU,所以转换成功必须满足cnt+6x==2的n次方。

    4、通过找规律,发现当cnt为2,4,8,10,14,16,20,22,26,28,32,34,38……时满足方程,这些数的共同特点是能被2整除,不能被3整除。

    5、当cnt为1时,即MI,也满足条件。

    6、满足4、5的大前提是M是字符串的第一个字母,且仅有一个。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    typedef long long ll;
    typedef unsigned long long llu;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
    const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const double eps = 1e-8;
    const int MAXN = 1e6 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    char s[MAXN];
    int main(){
        int T;
        scanf("%d", &T);
        while(T--){
            scanf("%s", s);
            int len = strlen(s);
            int cnt = 0;
            int m = 0;//M的个数
            bool ok = true;
            for(int i = 0; i < len; ++i){
                if(s[i] == 'I') ++cnt;
                else if(s[i] == 'U') cnt += 3;
                else ++m;
            }
            if(s[0] == 'M' && m == 1 && (cnt == 1 || (cnt % 2 == 0 && cnt % 3 != 0)))
                printf("Yes\n");
            else printf("No\n");
        }
        return 0;
    }
  • 相关阅读:
    Linux网卡设置
    Linux虚拟机-----概述(1)
    Redis缓存数据库-----概述(1)
    Spring和Mybatis的集成
    onehot编码解释
    LINUX-CUDA版本所对应的NVIDIA驱动版本号,cuda版本报错的朋友参考一下
    matplotlib画图
    pytorch实现花朵数据集读取
    轻量架构ShuffleNet V2:从理论复杂度到实用设计准则
    CBAM: 卷积块注意模块
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6357812.html
Copyright © 2011-2022 走看看