2011年3月10日

poj 2774

摘要: 后缀数组代码:#include<iostream>#include<fstream>using namespace std;int sa[200003],sa1[200003],rank1[200003];int rank[200003],y[200003],h[200003];int pow=1;char m[200004];int c[200003];int cmp2(const void *a,const void *b){ int x=*(int*)a; int y=*(int*)b; if(rank[x]!=rank[y]) return(rank[x]-ra 阅读全文

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

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)

2011年3月8日

poj 1852

摘要: 简单模拟,把所有蚂蚁看成一样的。#include<iostream>#include<fstream>using namespace std;int n,m;int main(){ int i,j,k; int K,ans,ans1,s,t;// ifstream cin("in.txt"); cin>>K; while(K--) { ans=0; ans1=0; cin>>n; cin>>m; for(i=1;i<=m;i++) { cin>>s; t=n-s; if(s>t) { k=t 阅读全文

posted @ 2011-03-08 19:31 宇宙吾心 阅读(307) 评论(0) 推荐(0)

poj 3150

摘要: 矩阵乘法,运用循环矩阵性质。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;long long map[501][501],map1[501][501],map2[501][501];long long m,d;long long k;long long a[501],b[501];int n;void solve(long long k){ long long i,j; if(k==1) { for(i=1;i<=n;i++) for(j=1;j< 阅读全文

posted @ 2011-03-08 19:02 宇宙吾心 阅读(413) 评论(0) 推荐(0)

poj 2118

摘要: 矩阵乘法。(a[n],a[n+1],a[n+2])=(a[0],a[1],a[2])*A^n.代码:#include<iostream>#include<fstream>using namespace std;int a[110];int map[110][110],map1[110][110],map2[110][110];int n;long long m;void solve(long long m){ int i,j,k; if(m==1) for(i=1;i<=n;i++) for(j=1;j<=n;j++) map1[i][j]=map[i][j 阅读全文

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

poj 1625

摘要: ac自动机+高精+dp高精输出适用了cout.wide cout.fill('0');代码:#include<iostream>#include<fstream>using namespace std;struct e{ int p[51]; int end;}trie[501];int n,m,K;int hash[600];int state=1;int f[501];void build(char c[]){ int i,j=0,k; for(i=1;;) { if(trie[i].p[hash[c[j]]]==0) trie[i].p[hash[ 阅读全文

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

poj 1177

摘要: 线段树,详见陈宏的论文。简单讲就是每两次覆盖之间的差值的总和。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;struct e{ int l,r,conut,size;}tree[5000*8];int a[20001];int b[20001];int a1[10001];int b1[10001];int n;struct xxx{ int s,t,f,x;}xx[10001];struct yyy{ int s,t,f,y;}yy[10001];void 阅读全文

posted @ 2011-03-08 10:45 宇宙吾心 阅读(914) 评论(0) 推荐(0)

2011年3月7日

poj 2528

摘要: 线段树,先离散化,再线段树。#include<iostream>#include<fstream>using namespace std;int x[10001],y[10001];int h[20001];int a[10000001];int v[10001];int cmp(const void *a,const void *b){ return *((int*)a)-*((int *)b);}struct e{ int l,r,color;}tree[80001];int n;void build(int l,int r,int p){ tree[p].l=l; 阅读全文

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

导航