摘要:
建树dfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 20005struct Edge{ int v, next;} edge[maxn * 2];int n, ecount;int head[maxn];int f[maxn];int ans, ansi;bool vis[maxn];void addedge(int a, int b){ edge[ecount 阅读全文
posted @ 2011-06-15 22:03
undefined2024
阅读(222)
评论(0)
推荐(0)
摘要:
给出八方向行走方案求路线圈出的面积。计算面积时总是算二倍的面积,这样就可以处理0.5的问题。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;int main(){ //freopen("t.txt", "r", stdin); int t; scanf("%d", &t); getc 阅读全文
posted @ 2011-06-15 21:07
undefined2024
阅读(401)
评论(2)
推荐(0)
摘要:
题意:给出两棵树的深度遍历序列,0表示远离根,1表示向根走。判断两树是否同构。分析:利用树的最小表示,定义S[t]表示以t为根的子树的括号序列S[t]={‘(‘,S[c1],S[c2],…,S[ck],’)’ (c1,c2,…,ck为t的k个子节点,S[c1],S[c2],…,S[ck]要按照字典序排列)}为了保证同构的树的括号序列表示具有唯一性,我们必须规定子树点的顺序。按照子树的括号序列的字典序就是一种不错的方法。真正操作的过程中要用深度优先遍历全树,当遍历完一个子树时要对这个子树根节点所连接的所有子节点进行排序。整个过程不需要建树,但是要记录每个子树对应的字符串的起始和结束位置。#inc 阅读全文
posted @ 2011-06-15 20:30
undefined2024
阅读(933)
评论(0)
推荐(1)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int lastdigit(char *buf){ const int mod[20] = { 1, 1, 2, 6, 4, 2, 2, 4, 2, 8, 4, 4, 8, 4, 6, 8, 8, 6, 8, 2 }; int len = strlen(buf), a[40], i, c, ret = 1; if (len == 1) re 阅读全文
posted @ 2011-06-15 19:06
undefined2024
阅读(210)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 1005int n, m;bool vis[maxn];int cost[maxn][maxn];int weight[maxn];void input(){ scanf("%d%d", &n, &m); memset(cost, 0, sizeof(cost)); for (i 阅读全文
posted @ 2011-06-15 18:22
undefined2024
阅读(226)
评论(0)
推荐(0)