摘要: 建树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)
摘要: 题意不好理解,其实是最小生成树。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 2005#define inf 0x3f3f3f3fint n;char code[maxn][10];int cost[maxn][maxn];int vis[maxn];int lowc[maxn];int cal(int a, int b){ int ret = 0; for (in 阅读全文
posted @ 2011-06-15 12:18 undefined2024 阅读(776) 评论(0) 推荐(0)
摘要: 1.理解了rmq的st算法。就是将每个大区间用刚好大于其长度一半的2^x的大小来将其分割为两个有重叠区间求解。即s~t被分为s~s + 2^x 和 t - 2^x + 1 ~t。吉大的第一个st是错误的。2.学会了笛卡尔树,即一个满足堆的大小性质的二叉搜索树,但不一定是完全二叉树。这是将rmq转为lca的关键。3.scanf的用法,%*[ ],表示越过[ ]中的字符,%[a-z]表示读入字符串,直到遇到不是a-z中的字符为止。%[^a]表示读入字符串直到遇到字符a为止,但a并没有被读入。题意:给出一些节点,每个节点有两个值,lable和priority(都是唯一的),要求构成一个笛卡尔树,按l 阅读全文
posted @ 2011-06-15 10:39 undefined2024 阅读(883) 评论(2) 推荐(0)