摘要: http://poj.org/problem?id=1984 题目描述的如此蛋疼。。。 关系并查集,用cx和cy数组记录点与根结点的相对位置,然后根据输入依次合并,当碰到询问时便计算距离,若不在同一集合中,即无法确定相对位置。code:#include<cstdio>#include<cstring>intp[40001],cx[40001],cy[40001];intf1[10001],f2[10001],fi[10001];structedge{ints,e,l;chard;}q[40001];intabs(inta){returna>0?a:-a;}void 阅读全文
posted @ 2012-04-21 21:15 追逐. 阅读(260) 评论(1) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2385 dp[i][j], i为第几分钟,j为走了几次。则dp[i,j]=max(dp[i-1,j-1], dp[i-1][j])+(data[i]==(j%2+1)?1:0)。对data[i]==(j%2+1)?1:0,若j为奇数,则其必在2号树下,所以+1,反之+0。code:#include<cstdio>usingnamespacestd;intdp[1005][35];intapp[1001];intmax(inta,intb){if(a>b)returna;returnb;}intmain(){inti,j,t 阅读全文
posted @ 2012-04-21 20:54 追逐. 阅读(231) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1226 求给定的字符串及其反串的最大公共子串。 后缀数组,将所有的字符串及其子串连接起来,用分隔符隔开,并给每个字符串及反串的字符标记所在串。二分答案,看是否有n个字符串或者其反串存在长为mid的公共前缀。code:#include<cstdio>#include<cstring>#defineMax(a,b)a>b?a:bconstintmaxn=10001;intwa[maxn],wb[maxn],wv[maxn],ws[maxn],rank[maxn],height[maxn],sa[maxn],s[ma 阅读全文
posted @ 2012-04-21 12:00 追逐. 阅读(206) 评论(0) 推荐(0) 编辑