您当前的位置: 首页 >  数学

钟钟终

暂无认证

  • 6浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

哈希+组合数学+思维

钟钟终 发布时间:2022-10-12 15:28:58 ,浏览量:6

B. Password

做法有很多,kmp、哈希都可以。wa麻了,调了2个小时才接受自己的做法有问题,固执。 思路: 1.可用哈希手法O(1)判断一个字符串的两端子串是否相同。 2.对字符串的长度进行二分,若这一段(从第二个字符~第n-1的字符)的哈希值等于首部、尾部字符串,则成立。 代码:

#include 
#define int long long
#define ios cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
#define endl '\n'
#define ULL unsigned long long
using namespace std;
const double eps=1e-8;
const int mod=998244353;
const int N=1e6+5;
const int P=131;
ULL p[N],h[N];
char s[N];
int a[N],n,cnt;
int init(char s[])
{
    p[0]=1,h[0]=0;
    int len=strlen(s+1);
    for(int i=1;i(s+1);
    n=strlen(s+1);
    init(s);
    for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0423s