2011年3月9日

poj 2513

摘要: trie+并查集,并查集判断联通情况。代码:#include<iostream>#include<fstream>using namespace std;int n;int f[500001];int rank[500001];int d[500001];void init(){ for(int i=1;i<=500000;i++) { f[i]=i; rank[i]=0; }}int father(int s){ if(s!=f[s]) s=father(f[s]); return f[s];}void unionset(int s,int t){ int i= 阅读全文

posted @ 2011-03-09 19:24 宇宙吾心 阅读(189) 评论(0) 推荐(0)

poj 1816

摘要: trie树上的搜索,数据太阴了,模式串有重复的。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int a; e *next;};struct { int p[60]; e end;}trie[600001];int m,n;int hash[128];int state=1;long long s;int v[100001];int f;void build(char c[]){ int i,j=0,k; for(i=1;;) { if(trie[i].p[hash[c[j]]]= 阅读全文

posted @ 2011-03-09 17:14 宇宙吾心 阅读(347) 评论(0) 推荐(0)

poj 2778

摘要: 自动机+矩阵乘。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int p[5]; int end;}trie[101];int m,K,n;int hash[128];int state=1;long long s;int f[101];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 阅读全文

posted @ 2011-03-09 15:26 宇宙吾心 阅读(1158) 评论(0) 推荐(1)

导航