2011年3月7日

poj 3368

摘要: 线段树/** 思路:在线段树的结点内设5个变量l、r、mx、lf、rf,[l,r]表示该结点的区间范围,* lf和rf分别表示元素a[l]和a[r]在区间内的出现频率,mx表示区间内的最高出现频率。* 假设区间[x,y]和[y+1,z]均被询问[i,j]覆盖,则可以分情况讨论区间[x,z]的mx值:* 若a[y]==a[y+1],则mx[x,y]=max{mx[x,y],mx[y+1,z],rf[x,y]+lf[y+1,z]}* 否则mx[x,y]=max{mx[x,y],mx[y+1,z]}**/代码:#include<iostream>#include<fstream&g 阅读全文

posted @ 2011-03-07 11:29 宇宙吾心 阅读(242) 评论(0) 推荐(0)

2011年3月5日

poj 3468

摘要: 经典线段树,大彻大悟了!!!代码:#include<iostream>#include<fstream>using namespace std;struct e{ int left,right; long long add; long long sum;};e tree[400011];long long a[100001];long long build(int s,int t,int num){ long long i,j; tree[num].left=s; tree[num].right=t; tree[num].add=0; if(s!=t) { i=buil 阅读全文

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

poj 1204

摘要: ac自动机的题。代码:#include <iostream>using namespace std;const int N=1010;int n,m,w;struct trie{ int nxt[27]; int num,fl,id,len;}ac[N*N];int q[N*N];char a[N][N],c[N];int idx;struct nod{ int x,y; char c;}ans[N];void add(char c[],int id,int len){ int p=0; for(int i=0;c[i];i++) { int x=c[i]-'A'; 阅读全文

posted @ 2011-03-05 19:43 宇宙吾心 阅读(420) 评论(2) 推荐(0)

poj 2777

摘要: 线段树题。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; int color;} tree[800001];int n,m,t;int v[31];void build(int s,int t,int p){ tree[p].l=s; tree[p].r=t; tree[p].color=1; if(t>s) { int mid=(s+t)>>1; build(s,mid,p*2); build(mid+1,t,p*2+1); }}void ins 阅读全文

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

poj 2352

摘要: 线段树题注意思想。代码:#include<iostream>#include<fstream>using namespace std;struct e{ int l,r; int cn;}tree[70000];int level[15001];int n;int x[15001],y[15001];int maxx;void build(int l,int r,int p){ tree[p].l=l; tree[p].r=r; tree[p].cn=0; if(l<r) { int mid=(l+r)>>1; build(l,mid,p*2); bu 阅读全文

posted @ 2011-03-05 10:37 宇宙吾心 阅读(670) 评论(0) 推荐(0)

2011年3月4日

poj 1229

摘要: dp题,神奇的替换:ONE 匹配一个单词ZERO_ONE 匹配零个或一个单词ANY 可以匹配零个或多个单词这样:* = ONE, ANY? = ONE, ZERO_ONE, ZERO_ONE! = ONE, ONE, ONE, ANY替换后即可dp。注意这个例子:a.b.?!.c (输出yes)代码:#include<iostream>#include<fstream>using namespace std;char c[400][300],c1[400][300];int n1,n2;char c2[120000];int n;bool dp[400][400];vo 阅读全文

posted @ 2011-03-04 17:19 宇宙吾心 阅读(460) 评论(0) 推荐(0)

poj 1200

摘要: 题目比较简单,hash即可。可惜犯了个低级错误,for(i=0;i+m-1<n;i++)(这里原来写错了!!)。 阅读全文

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

2011年2月27日

poj 1948

摘要: 题意:给定n根长度的木棍,求围成的三角形中面积最大的那个。找好状态就好办。dp[i][j][k]=dp[i-1][j][k]||dp[i][j-a[i]][k]||dp[i][j][k-a[i]];dp[i][j][k]表示前i跟木棒可构成长度j,与长度k。代码:#include<iostream>#include<fstream>#include<cmath>using namespace std;int n;int a[41];bool dp[41][1000][1000];int sum=0;int ok(int s,int t,int k){ dou 阅读全文

posted @ 2011-02-27 18:32 宇宙吾心 阅读(379) 评论(0) 推荐(0)

poj 2033

摘要: 题意:求解码方案个数。注意细节。如10,20只有一种解码方案,22有两种。代码:#include<iostream>#include<fstream>using namespace std;long long dp[1000001];int n;void read(){// ifstream cin("in.txt"); int i,j,k; char c[1000001]; while(1){ cin>>c; n=strlen(c); if(strcmp(c,"0")==0) return; memset(dp,0, 阅读全文

posted @ 2011-02-27 15:16 宇宙吾心 阅读(367) 评论(0) 推荐(0)

poj 1972

摘要: 少人做的水题。直接模拟即可,不算dp题。代码:#include<iostream>#include<fstream>using namespace std;int a[10001][7];int n;int ok(int s,int t){ int i=0; if(t==1) { i=max(a[s][2],i); i=max(a[s][3],i); i=max(a[s][4],i); i=max(a[s][5],i); } else if(t==2){ i=max(a[s][1],i); i=max(a[s][3],i); i=max(a[s][6],i); i=ma 阅读全文

posted @ 2011-02-27 14:42 宇宙吾心 阅读(281) 评论(0) 推荐(0)

导航