摘要: 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2141 这个题听虎哥给讲的,开始自己想的时候老是以为BFS就必须得用递归,这个题的思路没有想象的那么复杂啊。#include<stdio.h>#include<string.h>int p[101][101],ans[101],o[101];int main(){ int a,b,c,d,i,j,k,m,n; scanf("%d",&a); while(a--) { memset(a 阅读全文
posted @ 2012-05-27 19:09 Naix_x 阅读(194) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2129最裸的并查集。。模板代码,好久没打过了。#include<stdio.h>int p[1001];int find(int x){ int a=x; while(p[a]!=a) a=p[a]; return a;}void mermge(int x,int y){ int x1=find(x),y1=find(y); if(x1!=y1) p[x1]=y1;}int main(){ int... 阅读全文
posted @ 2012-05-27 17:25 Naix_x 阅读(199) 评论(0) 推荐(0)
摘要: 坑爹的百度空间升级之后,成那个熊样了。。。所以,转战博客园。题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1291 给出先序遍历和中序遍历,求后序遍历。代码参考白书上的。。 思路:先序遍历中第一个肯定是根节点,找到在此节点在中序遍历的位置,则左边为左子树,右边为右子树。递归下去,用一个字符串,存下后序遍历的过程。#include<stdio.h>#include<string.h>void build(int n,char *s1,char *s2,char 阅读全文
posted @ 2012-05-27 16:43 Naix_x 阅读(186) 评论(0) 推荐(0)