hdu4436 && cf#244D 后缀自动机

本文深入探讨了信息技术领域的核心概念,包括前端开发、后端开发、移动开发、游戏开发、大数据开发、开发工具等多个方面,详细阐述了每个领域的关键技术和实际应用场景,旨在为读者提供全面的技术视野。
hdu4436

#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <stack>

using namespace std;
#define ll long long 
#define eps 1e-8
#define inf 0x3f3f3f3f
#define N 100100
#define M 2002000
#define mod 2012

struct State
{
    State *par,*go[11];
    int len,id,pos,cnt,sum;
    State(){}
    State(int _len):len(_len)
    {
        cnt = sum = 0;
        par = 0;
        memset(go,0,sizeof(go));
    }
}*root,*last;
State nde[N<<1];
int sz;
State* newState(int len)
{
    nde[sz] = State(len);
    nde[sz].id = sz;
    return &nde[sz++];

}
State* newState(State* p)
{
    nde[sz] = *p;
    nde[sz].id = sz;
    nde[sz].cnt = nde[sz].sum = 0;
    return &nde[sz++];

}
void init()
{
    sz = 0;
    root = last = newState(0);
    nde[0].pos = 0;

}
void extend(int w,int len)
{
    State* p = last;
    State* np = newState(p->len+1);
    np->pos = len;
    last = np;
    while(p && p->go[w]==0)
        p->go[w] = np,p = p->par;
    if(p==0)
        np->par = root;
    else
    {
        State* q = p->go[w];
        if(p->len+1 == q->len)
            np->par = q;
        else {
            State* nq = newState(q);
            nq->len = p->len + 1;
            q->par = nq;
            np->par = nq;
            while(p && p->go[w]==q)
                p->go[w] = nq, p = p->par;

        }

    }

}
void build(char *str)
{

    last = root;
    for(int i=0;str[i];i++)
    {
        if( !last->go[str[i]-'0'] || !(last->go[str[i]-'0']->len == i+1 ) )
            extend(str[i]-'0',i+1);
        else
            last = last->go[str[i]-'0'];
    }


}

char ch[N];
int topocnt[N];
State *topsam[N<<1];


int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        init();
        for(int i=0;i<n;i++)
        {
            scanf("%s",ch);
            build(ch);
        }
        memset(topocnt,0,sizeof(topocnt));
        for(int i=0;i<sz;i++)
            topocnt[nde[i].len]++;
        for(int i=1;i<N;i++)
            topocnt[i] += topocnt[i-1];
        for(int i=0;i<sz;i++)
            topsam[--topocnt[nde[i].len]] = &nde[i];
        int ans = 0;
        root->cnt = 1;
        for(int i=0;i<sz;i++)
        {
            State *tmp = topsam[i];
            for(int j=0;j<10;j++)
            {
                if( i==0 && j==0 )    continue;
                if(tmp->go[j])
                {
                    State *q = tmp->go[j];
                    q->cnt = (q->cnt + tmp->cnt)%mod;
                    q->sum = (q->sum + tmp->sum*10+tmp->cnt*j)%mod;

                }

            }
            ans = (ans + tmp->sum)%mod;
        }
        printf("%d\n",ans);

    }

}



code of cf244D
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <stack>

using namespace std;
#define ll long long 
#define eps 1e-10
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define sqr(x) ((x)*(x))
#define lson (u<<1)
#define rson (u<<1|1)


#define N 100100
#define M 2002000




struct State
{
	State *par,*go[26];
	int val,rht;
	State():par(0),val(0)
	{
		memset(go,0,sizeof(go));
	}
};

State nde[N<<1],*cur;
int topocnt[N];
State *topsam[N<<1];

struct SuffixAc
{
	State *root,*last;
	char str[N];
	int n;
	void init(){
		root = last = cur++;
		n = strlen(str);
	}
	void extend(int w)
	{
		State* p = last;
		State* np = cur++;
		np->val = p->val + 1;
		while(p && p->go[w]==0)
			p->go[w] = np,p = p->par;
		if(p==0)
			np->par = root;
		else
		{
			State* q = p->go[w];
			if(p->val+1 == q->val)
				np->par = q;
			else {
				State* nq = cur++;
				memcpy(nq->go, q->go, sizeof q->go);
				nq->val = p->val + 1;
				nq->par = q->par;
				q->par = nq;
				np->par = nq;
				while(p && p->go[w]==q)
					p->go[w] = nq, p = p->par;

			}

		}
		last = np;

	}
	void build()
	{
		init();
		
		for(int i=0;i<n;i++)
			extend(str[i]-'a');
		
	}
	void getRight()
	{
		int tot = cur - root;
		int idx = root-nde;
		memset(topocnt,0,sizeof(topocnt));
		for(int i=0;i<tot;i++)
			topocnt[nde[i+idx].val]++;
		for(int i=1;i<=n;i++)
			topocnt[i] += topocnt[i-1];
		for(int i=0;i<tot;i++)
			topsam[--topocnt[nde[i+idx].val]] = &nde[i+idx];
		State *p = root;
		for (int i = 0; i < n; i++) {
			p = p->go[str[i] - 'a']; p->rht++;
		}
		for (int i = tot - 1; i > 0; i--){
			if (topsam[i]->par) topsam[i]->par->rht += topsam[i]->rht;
		}
	}
}suf[2];







int main()
{
	
	while(scanf("%s%s",suf[0].str,suf[1].str)!=EOF)
	{
		cur = nde;
		suf[0].build();suf[0].getRight();
		suf[1].build();suf[1].getRight();

		int ans = inf;

		for(int i=0;i<suf[0].n;i++)
		{
			int num1 = 0, num2 = 0;
			State *p = suf[0].root;
			State *q = suf[1].root;
			for(int j=i;j<suf[0].n;j++)
			{
				if(j-i+1>=ans) break;
				p = p->go[suf[0].str[j]-'a'];
				q = q->go[suf[0].str[j]-'a'];
				if(p) num1 = p->rht;
				if(q) num2 = q->rht;
				else break;
				if(num1==1 && num2==1)
					ans = min(ans,j-i+1);
			}
			
			
		}
		if(ans==inf) ans = -1;
		printf("%d\n",ans);

	}

}

<think>我们计划覆盖以下算法类型:数据结构、动态规划、图论、数学、字符串、计算几何、搜索、贪心、分治等。 题目来源包括:洛谷(Luogu)、LeetCode、Codeforces、AtCoder、HDU、POJ等。 我们将按照类型分类,每个类型选取若干经典题目,总数不少于50题。 注意:由于不同OJ的链接格式不同,我们将给出直接可访问的完整链接(部分可能需要用户有账号或平台公开访问)。 由于平台限制,部分国内平台链接可能需要登录,但题目编号和名称足够清晰。 以下是分类题目列表:</think>### 算法竞赛精选题目集(50+题) #### 一、数据结构(12题) 1. **线段树进阶** [P3373 线段树2](https://www.luogu.com.cn/problem/P3373) - 区间乘加混合操作 [CF52C Circular RMQ](https://codeforces.com/problemset/problem/52/C) - 环形区间最值 [P5490 扫描线](https://www.luogu.com.cn/problem/P5490) - 矩形面积并 2. **树状数组** [P3368 树状数组2](https://www.luogu.com.cn/problem/P3368) - 区间修改单点查询 [P3759 逆序对](https://www.luogu.com.cn/problem/P3759) - 带删除逆序对 3. **平衡树** [P3391 文艺平衡树](https://www.luogu.com.cn/problem/P3391) - Splay区间翻转 [P1486 郁闷的出纳员](https://www.luogu.com.cn/problem/P1486) - 带删除的平衡树 4. **分块/莫队** [P4137 Rmq Problem](https://www.luogu.com.cn/problem/P4137) - mex查询 [CF86D Powerful array](https://codeforces.com/problemset/problem/86/D) - 区间幂次和 --- #### 二、动态规划(10题) 1. **树形DP** [P2607 骑士](https://www.luogu.com.cn/problem/P2607) - 基环树DP [CF856C Eleventh Birthday](https://codeforces.com/problemset/problem/856/C) - 数位DP 2. **状态压缩** [P3959 宝藏](https://www.luogu.com.cn/problem/P3959) - 状压+DFS [CF11D A Simple Task](https://codeforces.com/problemset/problem/11/D) - 简单环计数 3. **斜率优化** [P3195 玩具装箱](https://www.luogu.com.cn/problem/P3195) - 经典斜率优化 [CF674C Levels](https://codeforces.com/problemset/problem/674/C) - 期望DP优化 --- #### 三、图论(10题) 1. **网络流** [P2764 最小路径覆盖](https://www.luogu.com.cn/problem/P2764) - DAG最小路径覆盖 [CF1082G Petya and Graph](https://codeforces.com/problemset/problem/1082/G) - 最大权闭合子图 2. **连通性** [P3388 割点](https://www.luogu.com.cn/problem/P3388) - 求割点 [CF123E Maze](https://codeforces.com/problemset/problem/123/E) - 期望路径计数 3. **生成树** [P2619 最小生成树](https://www.luogu.com.cn/problem/P2619) - 带权二分 [CF888G Xor-MST](https://codeforces.com/problemset/problem/888/G) - 异或最小生成树 --- #### 四、数学(8题) 1. **数论** [P3307 项链](https://www.luogu.com.cn/problem/P3307) - Burnside引理 [CF1119F Niyaz and Small Degrees](https://codeforces.com/problemset/problem/1119/F) - 度数限制生成树 2. **组合数学** [P6669 组合数问题](https://www.luogu.com.cn/problem/P6669) - Lucas+数位DP [CF1342E Placing Rooks](https://codeforces.com/problemset/problem/1342/E) - 错排问题 --- #### 五、字符串(5题) 1. **KMP/AC自动机** [P2444 病毒](https://www.luogu.com.cn/problem/P2444) - AC自动机+拓扑 [CF1207G Indie Album](https://codeforces.com/problemset/problem/1207/G) - AC自动机+DFS序 2. **后缀数组** [P2178 品酒大会](https://www.luogu.com.cn/problem/P2178) - 后缀数组+并查集 [CF123D String](https://codeforces.com/problemset/problem/123/D) - 后缀自动机 --- #### 六、计算几何(5题) 1. **凸包/旋转卡壳** [P1452 旋转卡壳](https://www.luogu.com.cn/problem/P1452) - 平面最远点对 [CF1045I Palindrome Pairs](https://codeforces.com/problemset/problem/1045/I) - 回文向量 2. **半平面交** [P3256 半平面交](https://www.luogu.com.cn/problem/P3256) - 凸多边形交 [CF1120C Compress String](https://codeforces.com/problemset/problem/1120/C) - 字符串DP --- #### 七、其他(10题) 1. **分治/CDQ** [P3810 三维偏序](https://www.luogu.com.cn/problem/P3810) - CDQ分治 [CF626F Group Projects](https://codeforces.com/problemset/problem/626/F) - 差值DP 2. **搜索/剪枝** [P1379 八数码](https://www.luogu.com.cn/problem/P1379) - A*搜索 [CF1100E Andrew and Taxi](https://codeforces.com/problemset/problem/1100/E) - 二分+拓扑 3. **交互题** [CF1167F Scalar Queries](https://codeforces.com/problemset/problem/1167/F) - 树状数组应用 [CF1523D Love-Hate](https://codeforces.com/problemset/problem/1523/D) - 随机化 --- ### 训练建议 1. **刷题策略**: ```mermaid pie title 题目类型分配 “数据结构” : 25 “动态规划” : 20 “图论” : 18 “数学” : 15 “其他” : 22 ``` 2. **每日计划**: - 上午:3题(数据结构+DP) - 下午:2题(图论+数学) - 晚上:1题(综合/难题) 3. **必备资源**: - [OI Wiki](https://oi-wiki.org/) 算法百科 - [Codeforces Problemset](https://codeforces.com/problemset) 按rating筛选 - [Luogu 题单广场](https://www.luogu.com.cn/training/list)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值