2011年3月16日

poj 3155

摘要: 最小割。二分方法中: while(begin<=end) { mid=(begin+end)>>1; build(mid); if(m*xx-solve()>0) begin=mid+1; else end=mid-1; }最后 end<ans*<=begin.最大权值为begin,但要求定点集,要用end。代码:#include<iostream>#include<fstream>#include<queue>#define xx 1000000using namespace std;int n;int c[1110][ 阅读全文

posted @ 2011-03-16 16:52 宇宙吾心 阅读(419) 评论(0) 推荐(0)

2011年3月15日

poj 3581

摘要: 十分易错的题,后缀数组与最小表示都可行,我用后缀数组做。注意:1. 必须可分成三段。2. 后缀数组最后一个字符应定义成最大数。3.求第二段与第三段的划分时,数组应扩成两倍,再求后缀数组。易错例子:85 0 3 1 2 3 1 4错误程序输出:05134132正确的应该是:05132134代码:#include<iostream>#include<fstream>using namespace std;#define N 400010int sa[N],sa1[N],rank[N],rank1[N],c[N],h[N];int m[N];int n,pow,count;i 阅读全文

posted @ 2011-03-15 15:20 宇宙吾心 阅读(311) 评论(0) 推荐(0)

poj 3691

摘要: ac自动机+dp#include<iostream>#include<fstream>using namespace std;struct e{ int p[5]; int end;}trie[1001];int n,m,K;int hash[300];int state=1;int f[1001];void build(char c[]){ int i,j=0,k; for(i=1;;) { if(trie[i].p[hash[c[j]]]==0) trie[i].p[hash[c[j]]]=++state; i=trie[i].p[hash[c[j]]]; j++; 阅读全文

posted @ 2011-03-15 13:54 宇宙吾心 阅读(669) 评论(0) 推荐(0)

poj 3294

摘要: 后缀数组,height的考察。代码:#include<iostream>#include<fstream>using namespace std;#define N 100200int sa[N],sa1[N],rank[N],rank1[N],c[N],h[N];int m[N];int n,pow,count;int cmp(const void *a,const void *b){ int x=*(int*)a; int y=*(int*)b; if(rank[x]!=rank[y]) return(1); else if(rank[x+pow]!=rank[y+ 阅读全文

posted @ 2011-03-15 10:43 宇宙吾心 阅读(412) 评论(0) 推荐(0)

2011年3月14日

poj 2396

摘要: 有上下界的网络流,非主流做法。#include<iostream>#include<fstream>#include<queue>using namespace std;int n;int c[250][250],pre[250],f[250][250];int d[250],flow;int v[250];typedef struct e{ int data; e *next;}e;e edge[250];int build(){ int i,j,k; queue<int> q; q.push(1); memset(d,0,sizeof(d)) 阅读全文

posted @ 2011-03-14 15:37 宇宙吾心 阅读(590) 评论(0) 推荐(0)

poj 1149

摘要: 网络流,重在建图(注意重边)。代码:#include<iostream>#include<fstream>#include<queue>using namespace std;int n;int c[105][105],pre[105],f[105][105];int d[105],flow;int v[105];typedef struct e{ int data; e *next;}e;e edge[105];int build(){ int i,j,k; queue<int> q; q.push(1); memset(d,0,sizeof( 阅读全文

posted @ 2011-03-14 12:16 宇宙吾心 阅读(384) 评论(0) 推荐(0)

2011年3月13日

poj 3261

摘要: 后缀数组,height的二分。#include<iostream>#include<fstream>using namespace std;#define N 20011int sa[N],sa1[N],rank[N],rank1[N],c[N],h[N];int m[N];int n,pow,count;int cmp(const void *a,const void *b){ int x=*(int*)a; int y=*(int*)b; if(rank[x]!=rank[y]) return(1); else if(rank[x+pow]!=rank[y+pow] 阅读全文

posted @ 2011-03-13 15:12 宇宙吾心 阅读(571) 评论(0) 推荐(0)

poj 3080

摘要: 后缀数组,二分求多串子串,height数组山的结构。#include<iostream>#include<fstream>using namespace std;#define N 620int sa[N],sa1[N],rank[N],rank1[N],c[N],h[N];char m[N];int n,pow,count;int cmp(const void *a,const void *b){ int x=*(int*)a; int y=*(int*)b; if(rank[x]!=rank[y]) return(1); else if(rank[x+pow]!=r 阅读全文

posted @ 2011-03-13 14:06 宇宙吾心 阅读(673) 评论(0) 推荐(0)

poj 3576

摘要: hash判断子树是否相同,并且自身的终结性要相同。代码:#include<iostream>#include<fstream>using namespace std;#define prim 99983struct { int end; int p[30];}tree[150001];int n,m;char c[30];int state;void build(char c[]){ int i,j,k; i=1; for(j=0;j<strlen(c);j++) { k=c[j]-'a'; if(tree[i].p[k]==0) tree[i]. 阅读全文

posted @ 2011-03-13 12:22 宇宙吾心 阅读(402) 评论(0) 推荐(0)

2011年3月10日

poj 1743

摘要: 后缀数组,经典,height数组的深入理解,想象一下山的形状就明白了。代码:#include<iostream>#include<fstream>using namespace std;#define N 20003int sa[N],sa1[N],rank[N],rank1[N],c[N],h[N],m[N];int n,pow;int cmp(const void *a,const void *b){ int x=*(int*)a; int y=*(int*)b; if(rank[x]!=rank[y]) return(1); else if(rank[x+pow] 阅读全文

posted @ 2011-03-10 18:01 宇宙吾心 阅读(316) 评论(0) 推荐(0)

导航