摘要: 求树中最长路的方法:任选一结点为根,找最深结点。并以最深结点为根,找最深结点,其深度即为所求。本题两次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)
摘要: 模拟View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 1005int n, m;int pos[maxn];void work(){ int a = n; int b = m; int cnt = 1; int i = 1; pos[a] = 0; putchar('.'); while (true) { int temp = a * 10 / b; . 阅读全文
posted @ 2011-09-21 09:58 undefined2024 阅读(164) 评论(0) 推荐(0)