21shengsai
touso
这个作者很懒,什么都没留下…
展开
-
哈希
loj 10034#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int mod1=1e6+3,mod2=1e6+9,p1=47,p2=79,N=3000;int tot=0,nxt[N+5],poi[mod1+5],end[N+5];void insert(int x,int y){ nxt[++tot]=poi[x]; poi[x]=to原创 2021-05-15 11:17:03 · 68 阅读 · 0 评论 -
ac自动机
hdu 2222题意:给定n个长度不超过50的有小写字母组成的单词 以及一篇长为m的文章,问有多少个单词在文章中出现了,多组数据#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int N=1e5+10;int ans,cnt,nxt[N],ch[N][30],bo[N],que[N];void make(char *s){ int u=1,l原创 2021-05-14 18:56:14 · 53 阅读 · 0 评论 -
Trie 字典树
poj 3630题意:给出n个串,问是否存在两个串,使得一个串是另一个串的前缀#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int N=1e5+10;const int Z=10;int T,n,tot;int ch[N][Z];//数组存储trie树 bool bo[N];char s[20];void clear()//初始化 {原创 2021-05-14 17:17:24 · 75 阅读 · 0 评论 -
常见字符串匹配算法
BFBrute_Force算法将模式串和匹配串进行匹配,模式串从第一个字符开始与匹配串进行匹配,如果不同则从第二个字符开始匹配,知道全部匹配#include<stdio.h>#include<string.h>#include<string>#include<iostream>#include<algorithm>using namespace std;int BF(string s,string t){ int i=0,j=原创 2021-05-14 15:25:07 · 82 阅读 · 0 评论 -
STL API
stringinsert(pos,str);//在pos前插入strinsert(int pos, int n, char c);//在pos前插入n个字符cs.substr(i,j)//取s的从i开始长度为j的一段字符串s.substr(i)//从i开始,直到结束,相当于s.substr(i,s,size()-i+1)reverse(a.begin(),a.end())//反转char s[10010],p;int l=strchr(s,p)-s;//返回p在s中第一次出现的位置find(原创 2021-05-14 11:23:37 · 161 阅读 · 0 评论 -
图着色
点着色顺序着色法#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s[30];//连续读入相邻关系的每行字符串 int edge[30][30];//邻接矩阵 int n;//中继器数目 int ans,c[30];//求得的顶点着色数,各顶点的颜色 int b[30];//每种颜色使用的标志b[i]=1表示 第i种颜色已经使用了 void g原创 2021-05-13 09:53:35 · 53 阅读 · 0 评论 -
欧拉公式
poj 2284欧拉公式:如果G是一个阶为n、边数为m、且含有r个区域的联通平面图,则有恒等式:n-m+r=2#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define eps 1e-10#define maxn 90000struct Point//点 { double x,y; Point(doub原创 2021-05-12 18:57:54 · 206 阅读 · 0 评论 -
关节点的求解
SPF#include<iostream>#include<string.h>#include<algorithm>using namespace std;int edge[1010][1010];//邻接矩阵 int vis[1010];//表示顶点访问状态 int node;//顶点数目 int tmpdfn;//在dfs过程中记录当前的深度优先搜索序数 int dfn[1010];//每个顶点的dfn值 int low[1010];//每个顶点的原创 2021-05-12 14:08:59 · 228 阅读 · 0 评论 -
二分图最大匹配(匈牙利算法)
例题#include<iostream>#include<string.h>#include<algorithm>using namespace std;int n,m;//地图大小 char map[100][100];//地图 int x[3030],y[3030];//x表示与xi匹配的y顶点,y表示与yi匹配的x顶点 int xs[300][300],ys[300][300]; //水平方向上的块编号 垂直方向上的块编号 int xn,yn1;/原创 2021-05-12 10:43:52 · 60 阅读 · 0 评论 -
树形dp_1
cilck here 入门题意:公司举办晚会,每个参加晚会的人都不想看到自己的直接上司,给出每个人的活跃度以及与上司的关系,求最大活跃度#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=6e3+10;int dp[maxn][2],f[maxn];//dp[i][0]表示不去 dp[i][1]表示去bool book[maxn];原创 2021-05-11 10:13:23 · 66 阅读 · 0 评论 -
状压dp_1
Click Here题意:有一个m*n的农场,1表示土地肥沃,可以种草,0表示土地贫瘠,不能种草,不能选择两块相邻的土地,问有几种种草方式#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;const int mod=1e8,maxn=1<<12;ll dp[20][maxn],h[20];int main原创 2021-05-10 21:42:05 · 87 阅读 · 0 评论 -
区间dp_01基础
Click Here题意:任意选取一个数,并与左右相邻的数相乘,求最大和#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int inf=0x3f3f3f3f;int main(){ int a[220],dp[220][220]; int n; scanf("%d",&n); for(int i=1;i<=n;i++) s原创 2021-05-10 21:01:20 · 110 阅读 · 0 评论 -
概率DP
Click Here题意:给出n张试卷,以及每张试卷的通过概率,求使得该公式最大的值x^(x/y)#include<stdio.h>#include<string.h>#include<math.h>#include<functional>#include<algorithm>using namespace std;int main(){ double dp[110][110],b[110]; int a[110]原创 2021-05-10 20:17:04 · 51 阅读 · 0 评论 -
最大流(标号法 Ford-Fulkerson算法)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1000,inf=1000010;//顶点个数最大值struct ArcType//弧结构{ int c,f;};ArcType edge[maxn][maxn];//邻接矩阵int n;//顶点个数int flag[maxn];//顶点状态 -1未标号 0已标号未检查 1标原创 2021-05-10 10:30:42 · 1676 阅读 · 0 评论 -
汉密尔顿回路
一、基本概念汉密尔顿通路:给定图G,若存在一条经过图中的每一个顶点一次且仅一次的通路,称为汉密尔顿通路。汉密尔顿回路:若存在一条回路,经过图中的每个顶点一次且进一次,称这条回路为汉密尔顿回路。汉密尔顿图:具有汉密尔顿回路的图称为汉密尔顿图。二、相关定理1.若无向连通图G(V,E)具有汉密尔顿回路,则对于顶点集合V的任意非空子集S,均有W(G-S)<=|S|成立。其中|S|表示集合S中边的数目,W(G-S)表示G-S中连通分量的数目。2.设G是具有n个顶点的简单图,如果G中每一对顶点度数之和原创 2021-05-10 08:53:30 · 3737 阅读 · 0 评论 -
欧拉回路
链接#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;const int maxn=1e5+10;#define inf 100000000int t,n;int od[30],id[30];//首尾字母的出度入读 int based[30];//第i个字母在这组单词中是否作为首尾字母 int parent原创 2021-05-04 21:30:37 · 68 阅读 · 0 评论 -
最短路(Floyd)
Click Here题意:有n个点,每个点的坐标给出,求第一个点到第二个点的最长路径的最短值。每条路径的长度为该条路径中最长的一段的长度,求所有路径的最小值(即最长路径的最小值)#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;double e[1010][1010];#define inf 0x3f3f3f3f原创 2021-05-03 10:05:09 · 49 阅读 · 0 评论 -
最短路(DijKstra)
Click Here题意:有n个农场,农场主需要从1号农场走到n号农场,所需要的最短路径是多少//DijKstra 模板题#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int inf=0x3f3f3f3f;int e[1010][1010],dis[1010];int book[1010];int main(){ int n,m; s原创 2021-05-03 10:00:32 · 54 阅读 · 0 评论 -
21moban
一、遍历1、Dfsclick here2、BfsI am Here二、树1、生成树与最小生成树2、克鲁斯卡尔(kruskalfind me3、普利姆(primboring三、最短路1、Dijksrtra2、Bellman-ford3、Spfa4、Floyd5、差分约束四、可行遍性问题1、欧拉回路2、中国邮递员问题3、汉密尔顿回路五、网络流问题1、网络最大流2、最小割3、流量有上下界的最大流和最小流4、最小费用最大流六、支配集与匹配1、边覆盖集与边独立集原创 2021-04-30 19:49:32 · 908 阅读 · 3 评论 -
普利姆
Agti-Net/*题意:将所有点连接成有向图,即N个点需要N-1条边,求最短距离*/#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;int dis[1010],book[1010],e[1010][1010];int a[1010][1010];int mai原创 2021-04-30 19:43:48 · 77 阅读 · 1 评论 -
克鲁斯卡尔
还是畅通工程#include<stdio.h>#include<algorithm>using namespace std;int n,a[10010],sum;struct node{ int x,y,z;};void init(){ int i; for(i=0;i<=n;i++) a[i]=i; return ;}int getf(int v){ if(a[v]==v) r原创 2021-04-30 19:13:12 · 87 阅读 · 1 评论 -
bfs搜索
Rescuex从r走到a,遇到.消耗一秒,遇到x消耗2秒,问最少需要多少秒#include<stdio.h>#include<queue>#include<stack>#include<string.h>#include<algorithm>using namespace std;int n,m;char a[1010][1010];int book[1010][1010];int d[4][2]={{0,1},{0,-1},原创 2021-04-28 21:47:26 · 82 阅读 · 0 评论 -
dfs搜索
Tempter of the bones为狗的位置,D为迷宫的门,S为时间,问在倒计时结束前狗能否逃出迷宫#include<stdio.h>#include<string.h>int n,m,t,flag;char a[1010][1020];int x1,x2,y1,y2;int book[1010][1010],d[4][2]={{0,1},{0,-1},{1,0},{-1,0}};void dfs(int x,int y,int z){ if(a[x]原创 2021-04-28 21:29:06 · 79 阅读 · 0 评论