上一页 1 ··· 69 70 71 72 73 74 75 76 77 ··· 182 下一页
摘要: 题意:求割点,并求出去掉每个割点图会被分成几个连通分支。分析:求割点除了tarjan算法,还有一种O(n^2)的算法,就是分别把每个点作为根,进行dfs,看根有几个子结点,如果大于一个则为割点否则不是割点。本题就是观察每个点为根时有几个子结点,去掉该点后的连通分支数等于其子结点数。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 1005struct Edge{ int 阅读全文
posted @ 2011-09-29 08:44 undefined2024 阅读(441) 评论(0) 推荐(0)
摘要: 求树中最长路的方法:任选一结点为根,找最深结点。并以最深结点为根,找最深结点,其深度即为所求。本题两次bfs解决View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 1005struct Point{ int x, y;}q[maxn * maxn];int n, m;char map[maxn][maxn];int dist[maxn][maxn];int dir[4][ 阅读全文
posted @ 2011-09-21 20:37 undefined2024 阅读(354) 评论(0) 推荐(0)
摘要: dfsView Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 10int n;char map[maxn][maxn];bool rook[maxn][maxn];int ans;int dir[4][2] ={{ 0, 1 },{ 1, 0 },{ 0, -1 },{ -1, 0 } };void input(){ for (int i = 0; i < n; i++ 阅读全文
posted @ 2011-09-21 15:08 undefined2024 阅读(249) 评论(0) 推荐(0)
摘要: Pick公式:平面上以格子点为顶点的简单多边形,如果边上的点数为on,内部的点数为in,则它的面积为area=on/2+in-1View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;struct Point{ int x, y;} s, e;int t, n;int gcd(int x, int y){ if (!x || !y) return x > y ? x : y; for (int 阅读全文
posted @ 2011-09-21 13:42 undefined2024 阅读(493) 评论(0) 推荐(0)
摘要: 高精度进制转换,java做View Code import java.io.*;import java.util.*;import java.math.*;public class Main { static int cal(char ch) { if (ch >= 'A' && ch <= 'Z') return (int)(ch - 'A' + 10); if (ch >= 'a' && ch <= 'z') return (int)(ch - ' 阅读全文
posted @ 2011-09-21 11:58 undefined2024 阅读(309) 评论(0) 推荐(0)
上一页 1 ··· 69 70 71 72 73 74 75 76 77 ··· 182 下一页