2020HDU多校第八场——Isomorphic Strings

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=6863

题意:
有一个长度为n的字符串,问能不能分解成k个子段,每个子段长度相同,而且字符串的最小表示相同。其中k要大于1;
判断输出Yes,No;
思路:
要想成功分解成k段,那么最少每段的字符数量要相同,而且还要被n整除,那么我们可以找到所有字符和n的公约数len,然后n/len就是最小的k,k每次可以增长一倍,但是要判断能不能被n整除(n可以整除k,但是n不一定就能整除2*k,这里开始忘了判断,疯狂的T,T到怀疑人生),然后判断每个字符串的不同种类就可以用map记录每一个的hash就行。
最后判断每一段的字符串hash值,在不在这些map已经记录的hash值中。

/*
 * @沉着,冷静!: 噗,这你都信!
 * @LastEditors: HANGNAG
 * @LastEditTime: 2020-08-14 17:45:38
 * @FilePath: \ACM_vscode\杭电多校\main.cpp
 */
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod = 13331;
const double eps = 1e-6;
const LL inf = 0x3f3f3f3f;
const LL N = 5e6 + 10;
LL num[30];
LL ha[N];
LL p[N];
char s[N];
map<LL, LL> mp;
int main()
{
    p[0] = 1;
    for (LL i = 1; i < N; i++)
    {
        p[i] = p[i - 1] * mod;
    }
    LL t;
    scanf("%lld", &t);
    while (t--)
    {
        LL n;
        scanf("%lld", &n);
        scanf("%s", s + 1);
        memset(num, 0, sizeof(num));
        ha[0] = 0;
        for (LL i = 1; i <= n; i++)
        {
            num[s[i] - 'a' + 1]++;
            ha[i] = ha[i - 1] * mod + (s[i] - 'a' + 1);
        }
        LL gg = n;
        for (LL i = 1; i <= 26; i++)
        {
            if (num[i])
                gg = __gcd(gg, num[i]);
        }
        LL u = n / gg;
        LL flog = 1;
        if (u == 1 && n != 1)
        {
            flog = 0;
        }
        else
        {
            for (LL i = 1; i < gg; i++)
            {
                LL len = i * u;
                if(n%len)
                {
                    continue;
                }
                flog = 0;
                mp.clear();
                LL k = ha[len] - ha[0] * p[len];
                mp[k] = 1;
                for (LL j = 1; j < len; j++)
                {
                    k = k * mod + (s[j]-96);
                    mp[k - ha[j] * p[len]] = 1;
                }
                for (LL j = 1; j * len <= n; j++)
                {

                    if (mp[ha[j * len] - ha[(j - 1) * len] * p[len]] == 0)
                    {
                        flog = 1;
                        break;
                    }
                }
                if (flog == 0)
                {

                    break;
                }
            }
        }
        if (flog == 0)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}




出现这个错误的原因是在导入seaborn包时,无法从typing模块中导入名为'Protocol'的对象。 解决这个问题的方法有以下几种: 1. 检查你的Python版本是否符合seaborn包的要求,如果不符合,尝试更新Python版本。 2. 检查你的环境中是否安装了typing_extensions包,如果没有安装,可以使用以下命令安装:pip install typing_extensions。 3. 如果你使用的是Python 3.8版本以下的版本,你可以尝试使用typing_extensions包来代替typing模块来解决该问题。 4. 检查你的代码是否正确导入了seaborn包,并且没有其他导入错误。 5. 如果以上方法都无法解决问题,可以尝试在你的代码中使用其他的可替代包或者更新seaborn包的版本来解决该问题。 总结: 出现ImportError: cannot import name 'Protocol' from 'typing'错误的原因可能是由于Python版本不兼容、缺少typing_extensions包或者导入错误等原因造成的。可以根据具体情况尝试上述方法来解决该问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [ImportError: cannot import name ‘Literal‘ from ‘typing‘ (D:\Anaconda\envs\tensorflow\lib\typing....](https://blog.youkuaiyun.com/yuhaix/article/details/124528628)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值