模板
文章平均质量分 79
淡定的小Y
一个暴躁的程序猿
展开
-
二分图最大匹配,点的最小覆盖,最小路径覆盖
vectorvec[N];bool vis[N];int n,k;int next[N+10];bool find(int t){ rep(i,vec[t].size()) { int m=vec[t][i]; if(vis[m]==false) { vis[m]=true; if(next[m]==-1 || find(next[m])) {原创 2013-07-24 10:13:18 · 498 阅读 · 0 评论 -
向量的叉积 凸包
向量的叉积(凸包)1. 向量的叉积的模表示这两个向量围成的平行四边形的面积。 设矢量P = ( x1, y1 ),Q = ( x2, y2 ),则矢量叉积定义为由(0,0)、p1、p2和p1+p2所组成的平行四边形的带符号的面积,即:P×Q = x1*y2 - x2*y1,其结果是一个伪矢量。 显然有性质 P × Q = - ( Q × P ) 和 P × ( - Q ) = - ( P × Q原创 2013-08-07 20:38:22 · 1440 阅读 · 0 评论 -
欧几里得扩展方程
ll x,y,m,n,l;ll a,b,c;ll k1,k2,d;ll gcd (ll x,ll y){ if(x<y) swap(x,y); if(y==0) return x; return gcd(y,x%y);}void fun(ll a,ll b){// cout<<a<<" "<<b<<endl; if(b==0) { k1=1; k2=0;d=a; r原创 2013-08-31 22:28:40 · 614 阅读 · 0 评论 -
最大匹配,花树开花算法
最初图是用的数组线性表存的,但是TLE了,后来直接用矩阵存的然后就AC了,表面上看用矩阵存似乎花的时间多,因为访问了一些不存在的边,但是用临接矩阵存有重边的情况就很不好,所以还是用矩阵吧!class match{public: queueq; int n,m,len; int g[N][N]; int pre[N]; int next[N],base[N],原创 2013-08-23 09:36:53 · 1933 阅读 · 0 评论 -
离散化的简单方法
for(int i=0;i //离散化的 pL=0;for(int i=0;i sort(p,p+pL),pL=unique(p,p+pL)-p;//排序去重的 for(int i=0;i a[i]=lower_bound(p,p+pL,a[i])-p;//返回就是在数组的位置的 //上面是离散化的一种方法的原创 2013-08-20 11:02:36 · 1039 阅读 · 0 评论 -
树链剖分 模板
class match{// #pragma comment(linker,"/STACK:100000000,100000000")扩栈语句啊!!public://top标记重边的头,w标记与其父节点相连的边在树中的位置,也为代表点的 int n,m,len,topw; int fa[N],size[N],son[N],w[N],top[N],dep[N]; int pre[N],li原创 2013-09-16 16:28:39 · 1442 阅读 · 0 评论 -
优先队列优化 dijkstra
#include #include #include #include #include #include #include #include #include #include #include using namespace std;#define LL long longconst int N = 30005;const LL INF = 1LL << 60;s原创 2013-07-17 11:35:38 · 1076 阅读 · 0 评论 -
后缀自动机 模板
class match{public://用m来定义字符串中字符的个数的,0~m-1 int son[N][M];//一般的是26个英文字母的,N为节点的个数 int fa[N],step[N];//fa指的是前面的那个的 int len,last; //len指的是总的节点的个数,last指的是横线上给的最多n个的 int node(int x) { step[+原创 2013-10-04 11:06:07 · 2060 阅读 · 0 评论 -
二分图的最大带权匹配
二分图最大带权匹配int lx[N],ly[N];int Stack[N],next[N];bool visx[N],visy[N];int n;vectorvec[N];bool bfs(int u){ visx[u]=true; rep(i,vec[u].size()) { if(visy[i]==true) co原创 2013-07-24 20:43:27 · 1304 阅读 · 0 评论 -
2-sat 问题 模板
int n,m,len,col,tot,ror;int dfn[N],low[N],pre[N];int stage[N],Stack[N];bool mark[N];struct node{ int y,pre;};node a[N];void init(){ len=1; col=0; tot=1; ror=1; memset(dfn,0,s原创 2013-08-10 16:01:55 · 982 阅读 · 0 评论 -
后缀数组 模板
char s[N];//数组的长度要为两倍的int n;//n全局变量为字符数组的长度的int sa[N],high[N],rank[N],tmp[N],top[N];void makesa(){ n=strlen(s);//代表的是长度的 n++; s[n]='$'; int na,len; na=(n<256?256:n);//字符中的最大的 memset(t原创 2013-08-26 17:04:43 · 873 阅读 · 0 评论 -
ac自动机
char s[60];char ss[1000100];struct node{ int fal; int sign; int p[26];};node a[N];int n,tot,ans;void tree(){ int len=strlen(s); int u=1; rep(i,len) { if(a[u].p[s[i]-'a']==-1)原创 2013-08-03 13:37:26 · 753 阅读 · 0 评论 -
最小覆盖圆(非)
最小覆盖圆模板/*==================================================*/ //| 求最小覆盖圆 //| CALL: 最小圆 = minC(Point *p,int n); /*==================================================*/ struct Point{double x原创 2013-08-07 20:44:32 · 664 阅读 · 0 评论 -
最小费用最大流 模板
class match{public://最大费用则加边的费用的值正好负号相反的 //s和t要赋值的,并且花费一个为正一个为负刚好抵消的 int s,t;//源点和结束点的,开始为1 的 struct node{ int y,cost,cap,pre; }; node a[N*1000]; int dis[N]; bool vis[N]; int point[N]; int原创 2013-10-25 20:59:38 · 671 阅读 · 0 评论 -
差分约束
①:对于差分不等式,a - b ②:对于不等式 a - b >= c ,建一条 b 到 a 的权值为 c 的边,求的是最长路,得到的是最小值 ③:存在负环的话是无解 ④:求不出最短路(dist[ ]没有得到更新)的话是任意解超级源点的建立很重要,是为了保证每个点都可以入队列判断负环,也可以一开始使得所有的点都进入队列的!建图时注意是带等于号的struct node原创 2013-08-25 15:58:22 · 539 阅读 · 0 评论 -
hdoj 3058 ac自动机+高斯消元
这道题和zoj2619的实质性是一样的,只不过这个中字符串的个数比较多,所以就需要建立自动机了,我的zoj上的题是直接用kmp的,只不过这道题麻烦却让我纠结了几天啊,感觉有的时候脑子就是不太会拐弯,就是不会转化的。不知道怎么用ac自动机去转化然后去建立数组,然后就今天下午在这里改了几乎一下午,挺搞笑的,一有思路就在那里改,然后改的多了就又回去找最原始的代码继续弄,好歹还是改出来了,现在自己想想原创 2013-08-09 19:49:49 · 663 阅读 · 0 评论 -
zoj 2619 KMP+高斯消元+概率求期望
这道题一下子最对挺高兴的,发现自己最近敲代码之前总是发愣,很没效率啊!!!用a[i]代表状态:尾部满足所给字符串长度i时为达到满足的字符串还所需要的期望。据此建立多元方程组然后进行高斯消元求解!/////////////////////////////////////////////////////////////////////////// File Name: 13614.cpp/原创 2013-08-07 20:29:59 · 1179 阅读 · 0 评论 -
最大流
#define N 10000 int n,m,len,s,t;struct node{ int x,y,e,pre;};node a[N*2];int pre[N],que[N],stage[N];void init(){ len=0; s=0; t=m+n+1;//s和t自己改的 memset(pre,-1,sizeof(pre));}void addpage(int原创 2013-07-24 10:12:17 · 424 阅读 · 0 评论 -
割点和割边
struct node{ int y,pre;};node a[N];int pre[N],sign[N];int dfn[N],low[N];int tot,lenn;int n,m,len;void init(){ memset(pre,-1,sizeof(pre)); memset(sign,false,sizeof(sign)); len=1;tot=1;}v原创 2013-07-24 10:09:45 · 677 阅读 · 0 评论 -
强联通分量
int n,m,len,col,tot,ror;int dfn[N],low[N],pre[N];int stage[N];//记录所在的强联通分量的 bool mark[N];int Stack[N];struct node{ int y,pre;};node a[N];void init(){ len=1,col=0;tot=1,ror=1;原创 2013-07-28 10:07:24 · 744 阅读 · 0 评论 -
字符串的最长回文字串
详细解释:http://blog.csdn.net/pi9nc/article/details/9251455char s[N];char str[N<<1];int rad[N<<1];int solve()//函数需要一个参数就是字符串s,返回的是其最长回文字串 { memset(str,'#',sizeof(str)); int len=strlen(s);原创 2013-07-26 15:24:29 · 678 阅读 · 0 评论 -
单调递增子序列
其实有点无语的就是求单调递增子序列的二分该怎么弄,我在各个oj上面试了递增和非递增数列就关于二分的时候等号加还是不加让我很郁闷,有的题等号加那边都对的,有的就不对,而且和我想的不太一样,我觉得应该对的却错了,看来二分需要好好恶补啊!暂且贴一个觉得试模板的吧!int a[N];int q[N]; int n;int main(){ while(~scanf("%d",&原创 2013-07-27 10:29:40 · 615 阅读 · 0 评论 -
点到线段之间的距离
double dis(node a,node b){ return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));}double solve(node pa,node pb,node pc){ double sum; double b,c,d; d=dis(pa,pc); b=dis(pb,pc); c=dis(pa,p原创 2013-07-30 09:59:11 · 587 阅读 · 0 评论 -
矩阵相乘
struct node { int mp[N][N]; node () { rep(i,N) rep(j,N) mp[i][j]=0; } node (int mp[N][N]) { rep(i,N) rep(j,N) this->mp[i][j]=mp[i][j]; } node operator *(node &a) { node c;原创 2013-08-07 20:32:08 · 612 阅读 · 1 评论 -
点到直线的距离
double fun(node s,node t,node p)//点到直线的距离,点p到点s和t确定的直线的距离 { if(fabs(s.x-t.x)<0.0000001) { return fabs(p.x-s.x); } double k=(s.y-t.y)/(s.x-t.x); double原创 2013-08-07 20:33:13 · 785 阅读 · 0 评论 -
高斯消元
void guess()//n行m列的矩阵a,且都为整数的{ rep(i,n) { int k=-1; repf(j,i,n-1) if(a[j][i]!=0) { k=j;break; } if(k==-1) continue;//这一列都为空的 if(k!=i) rep(j,m) swap(a[i][j],a[k][j]); re原创 2013-08-07 20:34:47 · 553 阅读 · 0 评论 -
树状数组模板
int lowbit(int x){ return x&(-x);}void update(int x,int y,int a)//在x,y中添加a{ int i,j; for(i=x; i<=n; i+=lowbit(i)) { for(j=y; j<=n; j+=lowbit(j)) { sum[i][j]+=a; if(sum[i][j]<0) s原创 2013-08-07 20:36:55 · 469 阅读 · 0 评论 -
差分约束系统
差分约束系统 ①:对于差分不等式,a - b = c ,建一条 b 到 a 的权值为 c 的边,求的是最长路,得到的是最小值 ③:存在负环的话是无解 ④:求不出最短路(dist[ ]没有得到更新)的话是任意解 第三: 一种建图方法: 设x[i]是第i位置(或时刻)的值(跟所求值的属性一样),那么把x[i]看成数列,前n项和为s[n],则x[i] = s[i] - s[i-1]; 那么这样就可以最起原创 2013-08-07 20:39:44 · 557 阅读 · 0 评论 -
字典树(非)
#include using namespace std;const int MAXM = 30,KIND = 26;int m;int sign;typedef struct fun{ char s1[25],s2[25];}rr;fun a[105];struct node{ char* s; int prefix; bool isword;原创 2013-08-07 20:41:57 · 465 阅读 · 0 评论 -
Rolya定理 最基本的环染色
int gcd(int x,int y){ if(y==0) return x; return gcd(y,x%y);}ll rolya(){ int i; ll sum=0; repf(i,0,n-1) sum+=(ll)pow(1.0*col,gcd(n,i)); if(n%2==0) { su原创 2013-08-07 20:46:45 · 944 阅读 · 0 评论 -
二维线段树模板
#define SQR(x) ((x)*(x))#define rep(i, n) for (int i=0; i<(n); ++i)#define repf(i, a, b) for (int i=(a); i<=(b); ++i)#define repd(i, a, b) for (int i=(a); i>=(b); --i)#define clr(ar,val) memset(ar原创 2014-10-29 20:34:46 · 1840 阅读 · 0 评论