搜索 DFS BFS
文章平均质量分 63
ChasingWaves
这个作者很懒,什么都没留下…
展开
-
POJ 2386
//160K 16MS #include #include #include #include using namespace std; struct point{ int x, y; }; const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; b原创 2014-07-18 16:52:30 · 355 阅读 · 0 评论 -
poj 3009 Curling 2.0
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10289 Accepted: 4339 Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are s原创 2014-04-11 18:05:24 · 373 阅读 · 0 评论 -
2014_3_29_周赛 马腿上的最短路
题目描述 在一个 n*m 的棋盘上有一些点已被己方棋子占用。有一只马要从点 S(x_s, y_s) 走到点 T(x_t, y_t) ,现求一个步数最少的方案。马的每一步是这样走的:先从起点 A 向上下左右任意方向走 1 格经过点 B,再顺时针或逆时针旋转 π/4 后走 sqrt(2) 格到达点C。但这是中国象棋里的马而不是国际象棋里的 knight,即如果经过的点 B 被占用,则会发生“蹩(原创 2014-03-30 00:08:06 · 583 阅读 · 1 评论 -
hdu 1372 Knight Moves
/*起点与终点一样的时候,单独拿出来 AC*/ #include #include #include #include using namespace std; struct node { int x, y; int step; }; bool vis[10][10]; int d1[8] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int d2原创 2014-03-27 21:40:28 · 337 阅读 · 0 评论 -
poj 3278
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42369 Accepted: 13178 Description Farmer John has been informed of the location of a fugitive cow and wants to catch h原创 2014-03-27 20:25:16 · 358 阅读 · 0 评论 -
2014_3_29_周赛 着火的最短路
题目描述 一个 n*m 的网格里有一些点着火了,火在每单位时间向八连通的相邻点蔓延。Alice 欲从点 S(x_s, y_s) 在最短时间内到达点T(x_t, y_t),她在每单位时间只能移动至四连通的相邻点。已经着火的点不能进入。 S 与 T 在时间零点上不着火。 输入格式 输入包含多组数据,以 EOF 结束。 对于每组数据,第一行包含两个整数 m,n。接下来 m 行原创 2014-03-30 01:30:41 · 573 阅读 · 0 评论 -
hdu 1372 解法二
/*改进版,不用vis数组,d数组为0表示没有访问过,非0的值表示到达所需的步数 AC*/ #include #include #include #include #include using namespace std; typedef pair P; int sx,sy; int ex,ey; int d[10][10]; int x[8]={1,1,2,2,-1,-1,-2,-原创 2014-03-27 22:23:24 · 442 阅读 · 0 评论 -
hdu 4771 Stealing Harry Potter's Precious
#include #include #include #include #include using namespace std; const int MAX = 105; const int INF = 0x7fffff; int n, m; char map[MAX][MAX]; bool vis[MAX][MAX]; int Move[4][2] = {{1, 0}, {0, 1}转载 2014-01-31 19:57:31 · 419 阅读 · 0 评论 -
校赛 D 小鑫的漂流
题目描述 小鑫有一天突然想去漂流,他来到一个既有小河又有土地的小岛上。他开始时站在岛的北面,还未上岛。现在他想要从岛的北面漂流到岛的南面去,由于有些地方可能被土地拦住,导致他无法直接顺着小河漂流到南面去。但小鑫有特殊的技巧,他可以挖穿土地,这样就可以顺利的漂到南面去了。小鑫又很懒,他想尽可能少的挖土,现在请问,他最少需要挖多少块土才能从岛的北面到南面去。 输入格式 第一行n, m原创 2014-04-22 13:30:58 · 544 阅读 · 1 评论 -
POJ 3411 Paid Roads 简单DFS
题目链接:http://poj.org/problem?id=3411原创 2014-06-19 17:43:33 · 394 阅读 · 0 评论 -
POJ 2718 Smallest Difference
DFS嵌套DFS //156K 47MS #include #include #include #include #include //不加此头文件min和abs在一起会出现编译错 using namespace std; const int inf = 0x7fffffff; int num[20]; bool usea[20], useb[20]; int cnt, cnta,转载 2014-07-16 20:17:02 · 365 阅读 · 0 评论 -
POJ 3050 Hopscotch DFS
//516K 63MS #include #include #include #include using namespace std; int a[6][6]; bool vis[6][6]; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; set s; int num; inline bool ok原创 2014-07-17 10:32:43 · 367 阅读 · 0 评论 -
POJ 3669 Meteor Shower BFS
//624K 63MS #include #include #include #include #include using namespace std; struct node{ int x, y, t; }; const int INF = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1,原创 2014-07-16 16:08:03 · 458 阅读 · 0 评论 -
POJ 3187 Backward Digit Sums
暴力搜索//156K 0MS #include #include #include #include using namespace std; int c[12][12]; int a[12]; void initc(){ memset(c, 0, sizeof(c)); c[0][0] = 1; for(int i=1; i<=10; i++){原创 2014-07-17 09:39:05 · 363 阅读 · 0 评论 -
2014_3_29_周赛 倒水
题目描述 两个容量分别为 a 和 b 的容器,通过三种操作,直到某一容器装有体积为 c 的水,同时另一容器为空,使倒水次数最少。初始时容器皆空。三种操作分别为:把某容器全倒到下水道;把某容器用水龙头接满;从甲容器向乙容器倒水直到甲空或乙满。 输入格式 每组数据包含三个整数 a, b, c。输入以 EOF 结束 输出 对于每组数据:若有解则输出最少的倒水次数;若无解则输出 No原创 2014-03-30 00:10:24 · 473 阅读 · 0 评论