上一页 1 ··· 6 7 8 9 10 11 12 下一页

2012年6月19日

hdu 2874 Connections between cities

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2874裸LCA,处理森林的无向图。思路:给每棵树一个唯一的编号,查LCA的时候,判断一下是不是在同一棵树下就行了。View Code #include<stdio.h>#include<string.h>#include<iostream>#include<vector>#include<iostream>#include<algorithm>#pragma comment(linker, "/STACK:36777216&qu 阅读全文

posted @ 2012-06-19 15:35 aigoruan 阅读(182) 评论(0) 推荐(0)

hdu 2586 How far away ?

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2586也是一道很裸的LCA,只不过卡了一下栈,要自己开大点栈才能过(c++)。思路:选1为根节点,先得到从根节点出发到每个点的距离,这样任意两个点的距离为:dis(u)+dis(v)-2*dis(lca(u,v)).View Code #include<stdio.h>#include<string.h>#include<iostream>#include<stdlib.h>#include<vector>#include<algorithm& 阅读全文

posted @ 2012-06-19 11:58 aigoruan 阅读(205) 评论(0) 推荐(0)

poj 1470 Closest Common Ancestors

摘要: http://poj.org/problem?id=1470裸LCA:读入数据很诡异。View Code #include<stdio.h>#include<string.h>#include<iostream>#include<vector>#include<algorithm>#include<stdlib.h>using namespace std;const int maxn = 1000;struct nd{ int to,next;}edge[maxn*2];vector<int>qes[maxn] 阅读全文

posted @ 2012-06-19 10:45 aigoruan 阅读(176) 评论(0) 推荐(0)

poj 1330 tarjan lca

摘要: http://poj.org/problem?id=1330tarjan 求解lca主要利用并差集的想法:首先遍历树,从叶子节点开始向上合并成一棵棵的子树,然后子树并子树,就成了一棵树了。查找是在合并的时候进行的,exp:u是s,t的lca,先从u节点进入s,把s并到u下面,然后发现t没有被访问,退到u,再进入t,同样把t并到u下面,发现s被访问过了,那么s的lca也就是s,t的lca了,也就是并差集里的f[s]。当然,f[s]会变的:假设当前f[s] = u; f[u] = u; 当u并到v的时候,也就是f[u]=v; 相应的f[s] = v。这也就是tarjan求解lca的关键方法。这个题 阅读全文

posted @ 2012-06-19 09:58 aigoruan 阅读(244) 评论(0) 推荐(0)

2012年6月18日

hdu 2242

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2242题目大意:给一个教室群,问能不能把这些教室群分成两部分,并且使两部分之间的权值差最小(每一个教室都有一定的权值);思路:先用双联通进行缩点,因为那些双向连通的教室肯定是分不开的,所以要把它们缩成一个点。之后再重新建图,遍历一次树!需要注意一点这道题的数据包含重边,需要考虑!!View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int N = 10005;struct nd{ int 阅读全文

posted @ 2012-06-18 14:34 aigoruan 阅读(150) 评论(0) 推荐(0)

hdu 1116

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1116简单欧拉回路判定:当是单向欧拉回路时,必须保证每个结点入度等于出度。当是单向欧拉路时,必须保证除了两个结点外,每个结点的入度等于出度,但这两个结点中,一个结点的入度比出度大1,另一个结点的入度比出度小1。View Code #include<stdio.h>#include<string.h>int IN[30],OUT[30];int F[30],D[30];char as[1005];int f(int x){if(x!=F[x]) x = f(F[x]); return x 阅读全文

posted @ 2012-06-18 10:44 aigoruan 阅读(190) 评论(0) 推荐(0)

2012年6月12日

uestc 1717

摘要: http://www.acm.uestc.edu.cn/problem.php?pid=1717&cid=169题意:先给一棵树,有n个结点(n<10^5),相邻的结点有距离;如果在这棵树上添加一条边后,查询两个点的距离是否改变近了,如果变近了,输出变近了多少。否则输出0。这个题是一个很好的练dfs的题,比赛的时候是郭化权做的,自己去弄线段树去了,不过线段树也是做不出来的~~~~。赛后想了想,觉得不是很难,结果弄了两天才出来,悲剧呀。还是郭化权的思路慎密。思路:在树上面加入一条边后,一定会有一个环出现的。仔细想想之后,最后要处理的都会归到这个环上的,因为只有要环里面的才可能出现距 阅读全文

posted @ 2012-06-12 19:15 aigoruan 阅读(372) 评论(0) 推荐(0)

xmu 1317

摘要: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1317题意:对于一个集合S,定义三种操作:1.加入一个数n;2.删除一个数n;3.查询第k大的数。解法:树状数组+map。View Code #include<stdio.h>#include<string>#include<map>#include<set>#include<vector>#include<string.h>#include<iostream>#include<algorithm># 阅读全文

posted @ 2012-06-12 17:44 aigoruan 阅读(153) 评论(0) 推荐(0)

2012年6月7日

hdu 2328 Corporate Identity

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2328题意:求多个字符串的最长公共子串,若有多个输出字典序最小。思路:先进行后缀数组操作。然后二分子串长度,根据height和sa数组的值,判断当前长度是否合适。当然,这里面还有hash映射的。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>const int maxn = 910000;int wn[maxn],wa[maxn],wb[maxn],wv[maxn],as[maxn],sa[max 阅读全文

posted @ 2012-06-07 21:01 aigoruan 阅读(157) 评论(0) 推荐(0)

hdu 1711 Number Sequence

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1711题意:给两个数字序列,判断第一个是否包含了第二个数列。思路一(正解):直接kmp;思路二(YY):求出第一个序列的前缀和,在第一个序列中取和第二个序列等长的子序列,如果这个子序列的和与第二个序列的和一样,才进行匹配算法。这个算法可以过不了一些特殊的数据。但在很短的时间内过了。View Code #include<stdio.h>#include<string.h>long long as[1000005],bs[10005],cs[1000005];int check(long 阅读全文

posted @ 2012-06-07 15:49 aigoruan 阅读(190) 评论(0) 推荐(0)

上一页 1 ··· 6 7 8 9 10 11 12 下一页

导航