赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  103 随笔 :: 0 文章 :: 41 评论 :: 96617 阅读

07 2012 档案

摘要:1. 写得最有逻辑的一道题了,10次讲座学的最好的就是DFS和BFS了。2. 直接深搜#include #include #include #include #include #include #include #include #include #include using namespace std; int a, b, sx, sy; char map[25][25]; int num[25][25]; bool flag[25][25]; int dir[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0... 阅读全文
posted @ 2012-07-10 16:25 赵乐ACM 阅读(153) 评论(0) 推荐(0) 编辑

摘要:#include #include #include #include #include #include #include //#include #include #include const int INT_MAX = (1 d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j]; } int main() { int n, j, i, a, b, m; while (cin >> n) { if (!n) break; ... 阅读全文
posted @ 2012-07-10 15:27 赵乐ACM 阅读(137) 评论(0) 推荐(0) 编辑

摘要:定义:除了1和其本身,没有其他约数的数。测试:用n分别试除2到sqrt(n)的数,如果中间有一个能整除,即为合数,否则即为素数bool is_prime(int n)//判断n是否为素数,是素数返回1 { int i; bool flag = 1; for(i = 2; i i)Prime[++q] = i; } } 大范围内筛素数的普通筛法(很慢):#define Max 1000000 int Prime[500000]; bool IsPrime[Max] = {1}; int q; void get_prime() { q = -1; ... 阅读全文
posted @ 2012-07-08 21:54 赵乐ACM 阅读(235) 评论(0) 推荐(0) 编辑

摘要:#include #include #include #include #include #include #include using namespace std; int num[5845]; void f() { int i, j, k, l, temp; i = j = k = l = 2; memset(num, 0, sizeof(num)); num[0] = num[1] = 1; int num1, num2, num3, num4; for (int m = 2; m > n) { if... 阅读全文
posted @ 2012-07-08 14:00 赵乐ACM 阅读(161) 评论(0) 推荐(0) 编辑

摘要:1. 简单的bfs,有用双向bfs的,但是为了赶进度,以后用双向bfs实现#include #include #include #include #include #include #include using namespace std; int dir[8][2] = {{-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}}; int flag[301][301], step[301][301]; int n, len, i; struct Node { int x, y; } ... 阅读全文
posted @ 2012-07-07 15:13 赵乐ACM 阅读(270) 评论(0) 推荐(0) 编辑

摘要:1. 并查集,有点忘了,看维基百科回顾起来了,三个操作,路径压缩、合并、查找父节点。代码很简单,具体参考http://zh.wikipedia.org/wiki/%E5%B9%B6%E6%9F%A5%E9%9B%862. WA了好多次,最后发现是当空树的时候也是一棵树,fuck。。。#include #include #include #include #include #include #include #define maxn 1000 using namespace std; int p[maxn], flag[maxn]; int getfather(int x) { ... 阅读全文
posted @ 2012-07-07 09:53 赵乐ACM 阅读(125) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示