
搜索
文章平均质量分 64
王猛旗
在读研究僧
展开
-
1319
//题意:最短路+方向//在搜索的时候加上方向;//良辰的代码#include#include#includeusing namespace std;char map[200][200];int use[200][200][4],n,m;int dir[5][2]={0,0,-1,0,1,0,0,-1,0,1};//原点,上下左右struct node{ int原创 2016-04-27 20:05:36 · 569 阅读 · 0 评论 -
HDU 2579/BFS/ Dating with girls(2)
题目链接/*题意是是传统的迷宫加上一个条件,墙壁在k的整倍数时刻会消失,那么求到达出口的最短时间。关键点在于某个点最多被走k次,标记vis[x][y][time%k]即可。*/#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std原创 2016-08-14 10:33:56 · 381 阅读 · 0 评论 -
HDU 1072/BFS
题目链接NightmareTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10069 Accepted Submission(s): 4910Problem Description Ignatius had a nightmare原创 2016-08-13 16:00:30 · 233 阅读 · 0 评论 -
HDU<1372>/bfs
题目连接简单dfs搜索#include <set>#include <map>#include <cmath>#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef pair<int, int> pa;原创 2016-07-31 19:05:49 · 368 阅读 · 0 评论 -
4位开锁<dfs>
题意: 有一个四位密码的锁,每一位是1~9的密码,1跟9相连。并且相邻的连个密码位可以交换。每改变一位耗时1s,给出锁的当前状态和密码,求最少解锁时间。 思路: 用bfs枚举出所有相邻交换的情况,并记录时间,然后每一位与密码比较,得出最少时间。注意输入的是一个数字,要把每一位提取出来。 代码:#include <iostream>#include <cstring>#i转载 2016-07-28 21:49:58 · 552 阅读 · 0 评论 -
Sticks<DFS>
题意:给n个木棍,这些木棍是由m个长度均为L的木棍切割而来,求L的最小值。思路:DFS+剪枝。剪枝:1:L的取值范围在n(max)和n(sum)之间,逐个枚举。sum%L!=0则L不能用。2:sort对n个木棍长度进行由小到大排序,有以下好处: a:从大的开始搜索。eg:如果L8;5+3>(优势)5+2+1;把更灵活地木棍留下来。 b:查找更有序。3:如果有一个木棍无法和其他原创 2016-05-29 21:30:38 · 494 阅读 · 0 评论 -
HDOJ1312<DFS>
题意:给一张图,有墙,有路。问某人从起点开始,最多能走多少个格子。思路:bfs;#include#includechar maze[25][25];int visit[25][25];int dir[4][2]={0,1,1,0,0,-1,-1,0};//方向int W,H,sum;void dfs (int s,int e){ for(int i=0;i<4原创 2016-04-21 14:02:31 · 462 阅读 · 0 评论 -
n皇后问题<dfs>
n皇后问题指的是:n*n的国际象棋棋盘上摆放n个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。和一般n皇后问题不同的是,现在棋盘上有可能已经放了一个皇后了。你能求出有多少合法的方案吗?多组数据。第一行有两个数n和m,n<=13表示棋盘大小,m<=1表示棋盘上已经有m个皇后了。下面m行,每一行有两个数x、y(x,y输出方案数思路:对于原创 2016-05-08 14:55:21 · 853 阅读 · 0 评论 -
8数码,欺我太甚!<bfs+康拓展开>
不多述,直接上代码,至于康拓展开,以前的文章里有#include#include#includeusing namespace std;int fac[]={1,1,2,6,24,120,720,5040,40320,362880};//阶乘表int dir[4][2]={1,0,0,1,-1,0,0,-1};//方向int vis[362881];int kangst,kang原创 2016-05-03 22:05:22 · 434 阅读 · 0 评论 -
1381: Munching(BFS)
DescriptionBessie loves her grass and loves to hurry to the barn for her eveningmilking session. She has partitioned the pasture into a rectilineargrid of R (1 <= R <= 100) rows and C (1 <= C原创 2016-04-04 09:58:47 · 381 阅读 · 0 评论 -
1107: 单向公路(bfs+输入整理)(DFS也可以,而且更快)
Description某个地区有许多城镇,但并不是每个城镇都跟其他城镇有公路连接,且有公路的并不都能双向行驶。现在我们把这些城镇间的公路分布及允许的行驶方向告诉你,你需要编程解决通过公路是否可以从一个城镇到达另一个城镇。(我们规定,城镇自己跟自己可互相到达,即A可到达A).Input第一行只有一个数N,下面将跟着2N行数据.在前N行数据中,对于每行数据,原创 2016-04-05 16:14:24 · 827 阅读 · 0 评论 -
Best Grass
DescriptionBessie is planning her day of munching tender spring grass and is gazingout upon the pasture which Farmer John has so lovingly partitioned into agrid with R (1 <= R <= 100) rows and原创 2016-04-03 14:15:15 · 537 阅读 · 0 评论 -
1209:Catch That Cow(bfs)
题意:从一个坐标到另一个坐标的移动方式有三种,即:st-1,st+1,2*st。每移动一步时间是一秒。给出两个坐标,求得从第一坐标到第二座标的最短时间。#include#include#include#includeusing namespace std;const int maxn=100005;int step[maxn];int st,ed;void bfs(){原创 2016-04-06 13:19:24 · 313 阅读 · 0 评论 -
1317: Square(DFS+剪枝)
DescriptionGiven a set of sticks of various lengths, is it possible to join them end-to-end to form a square?InputThe first line of input contains N, the number of test cases. Each原创 2016-04-04 08:55:34 · 351 阅读 · 0 评论 -
Power oj2470/DFS
题目链接 2469: C 小Y的难题(1) Time Limit: 1000 MS Memory Limit: 65536 KB Total Submit: 9 Accepted: 7 Page View: 128 Submit Status Discuss Description 最近小Y迷上了数学,总是在思考各种数学问题。有一天,他不小心把墨水洒在草稿纸上。他现在能看到的是“2?3?原创 2016-08-14 21:06:27 · 513 阅读 · 0 评论