上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 18 下一页
摘要: http://www.bianchengla.com/practise/problem?id=1387 第一道后缀数组,求出最大的height值即可。更多的是当个模板用吧。code:#include<cstdio>//最长重复子串#include<cstring>constintmaxn=10001;intwa[maxn],wb[maxn],wv[maxn],ws[maxn],rank[maxn],height[maxn],sa[maxn],s[maxn];charstr[maxn];intcmp(int*r,inta,intb,intl){returnr[a]==r[ 阅读全文
posted @ 2012-04-03 19:25 追逐. 阅读(253) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3332 看XSY博客有这题,就做一下,结果够让人郁闷的,太粗心了... 一开始用的宏比较多,出了个没见过的错Segmentation Fault ,这个好像类似与POJ的RE,内存错误。搞不懂,直接去掉了宏。 然后就开始WA了,impossible写成了impossbile,改正,依旧WA,发现i是大写的... 继续改正,还是WA,换了好多种dfs的方式,没用。没办法,瞎改吧。把dfs中定义的全局变量j改成局部变量,AC了... 这么简单的一道暴搜搞成了这个样子,引以为戒 阅读全文
posted @ 2012-04-02 15:22 追逐. 阅读(458) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2686 多进程DP,昨天第一次听说... 题目大意是找两条从(1, 1) 到(n, n)的路径,使权值和最大且节点不重叠。 让两个进程同时进行,枚举步数K,当x1==x2||y1==y2时跳过,得状态转移方程: dp(k, x1, y1, x2, y2) = max(dp(k-1, x1-1, y1, x2-1, y2), dp(k-1, x1-1, y1, x2, y2-1), dp(k-1, x1, y1-1, x2-1, y2), dp(k-1, x1, y1-1,x2, y2-1)) + ... 阅读全文
posted @ 2012-03-25 14:30 追逐. 阅读(410) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2157 算是细节比较多的搜索题了吧,考虑的时间比较长,最终代码写的也是那么的纠结。。。去真的不知道为什么RE啊!重新敲了一遍,完全一样的思路,然后就A掉了!搞毛啊?!白白浪费一下午找bug啊...#include<cstdio>#include<cstring>intkey[6],temkey[6];inttur[4][2]={0,1,0,-1,1,0,-1,0};boolvis[21][21];charmap[21][21];intn,m,sx,sy;structnode{intx,y;}q[500],door[6 阅读全文
posted @ 2012-03-23 19:04 追逐. 阅读(344) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1606 猛一看没思路,仔细想想,记住当前a,b水量及操作就可以bfs了,纯粹的暴力啊。。 输出需要路径,要在node中用指针记录当前状态的前一状态,根据oper输出即可。code:#include<cstdio>#include<cstring>inta,b,n,h,r;boolvis[1001][1001];intans[100001];structnode{intva,vb,oper,pre;}queue[1000001];voidoutput(){inti=1;ans[0]=queue[h].oper;h=qu 阅读全文
posted @ 2012-03-17 22:05 追逐. 阅读(340) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3009 其实一开始就想把dir当作参数,根据map条件搜索,但是却是在递归中用while处理的,处理不好map由0变1的回溯. 蛋疼的代码,看着就纠结。。code:#include<cstdio>#include<cstring>#defineMin(a,b)a>b?b:a#defineMAX1e+6inttur[4][2]={0,1,0,-1,1,0,-1,0};intmap[21][21];intw,h,ans,sx,sy,ex,ey;boolcheck(intx,inty){if(x<0||x> 阅读全文
posted @ 2012-03-16 19:48 追逐. 阅读(245) 评论(1) 推荐(1) 编辑
摘要: http://poj.org/problem?id=3256 对N个牧场用邻接表存储路径,记录下每个牧场初始牛的数目,沿路径dfs求连通牧场的牛数和。code:#include<cstdio>#include<cstring>usingnamespacestd;intnum[1001];intsum[1001];inthead[1001];boolvis[1001];intx;structpast{intv,nex;}edge[10001];voidaddedge(intu,intv){edge[x].v=v;edge[x].nex=head[u];head[u]=x; 阅读全文
posted @ 2012-03-14 20:53 追逐. 阅读(251) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 用到的主要是回溯,递归时先将所有字符放入栈中,在回溯时判断字符是否出栈并记录路径。栈是用字符数组模拟的。 另外这题的输出有点扯,每一行的最后一个i或o后面是有空格的,不需要处理,PE一次。code:#include<cstdio>#include<cstring>usingnamespacestd;charstr[50];charbstr[50],estr[50],ans[100];intblen,temp,h,r;voiddfs(intb 阅读全文
posted @ 2012-03-13 21:17 追逐. 阅读(273) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1564http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1711 简单深搜,主要是这一句 if(!vis[i]&&data[i]<=sum&&(data[i]!=data[i-1]||i==pos))。 确保两个连续的相同的数只有一次机会进入ans[],避免了结果的重复。code:#include<cstdio>#include<cstring>intdata[15];intans[15];boolvis[1 阅读全文
posted @ 2012-03-11 21:13 追逐. 阅读(187) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2965 16个位置分别有两个状态,用一个16位的二进制表示,对beg按位或运算得到初始状态,bfs中,用只包含0,1的16进制数实现翻转操作。 剩下的就是单纯的bfs了。code:#include<iostream>#include<cstdio>#include<cstring>usingnamespacestd;intdir[16]={0x111f,0x222f,0x444f,0x888f,0x11f1,0x22f2,0x44f4,0x88f8,0x1f11,0x2f22,0x4f44,0x8f88, 阅读全文
posted @ 2012-03-11 19:57 追逐. 阅读(209) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 18 下一页