随笔分类 -  搜索

摘要:题目连接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1286代码:#include<stdio.h>#include<limits.h>#include<string.h>#include<queue>using namespace std;int step[101][101][101]; //行,列,价值。step记录最小步数。char map[101][101];int n, m, tot;struct now { int 阅读全文
posted @ 2012-11-09 09:57 小猴子、 阅读(411) 评论(0) 推荐(0)
摘要:题目链接 http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1042思路:卒子所在行枚举答案,然后dfs求解。/* * hrbust1042过河卒 * 思路:卒子所在行枚举答案,然后进行不重复深搜。 */#include<stdio.h>#include<string.h>#include<algorithm>using namespace std; char res[10]; //记录卒子所在行的状态,用来枚举当前行。char map[6][10 阅读全文
posted @ 2012-11-07 00:22 小猴子、 阅读(428) 评论(0) 推荐(0)
摘要:题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=649大致题意:求r到a最少用多长时间,走到‘.'的时间为1,走到‘x'的时间为2,’#‘不能走。代码:#include<stdio.h>#include<string.h>#include<limits.h>#include<algorithm>#include<queue>using namespace std;#define M 201char map[M][M]; //存放地图。int 阅读全文
posted @ 2012-11-04 17:32 小猴子、 阅读(264) 评论(0) 推荐(0)
摘要:题目连接http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1317题目大意 如何根据一系列堆栈操作实现回文构词法呢?有两种堆栈的操作,将单词TROT转换成TORT。 i代表入栈,o代表出栈。对给定的单词对,编程实现堆栈操作,将第一个单词转换为第二个单词。 有多行输入。每两行的第一个是源单词(不包括换行符),第二行是目标单词(也不包括换行符)。由文件结束符标志输入结束。 对每对单词,有多种有效的方法从源单词产生目标单词,将每种方法的i和o操作排序输出,并以[]分隔。排序的方法是字典序。 阅读全文
posted @ 2012-11-03 22:58 小猴子、 阅读(477) 评论(0) 推荐(0)
摘要:题目连接:http://poj.org/problem?id=1979大致题意:给出两个数m和n,代表n行m列,都不超过20,然后是n行m列的图,包括'.' , '#' , '@'3个字符。@代表你的位置,'.'代表通路,‘#’代表墙,问你最远不回头能走几个‘.' 。‘@’算一个。输入0 0 结束。题意本不是这样,被我该了。。。意思不变#include<stdio.h>#include<string.h>char map[22][22];int m, n, ans;int dir[4][2] = { 阅读全文
posted @ 2012-11-03 18:25 小猴子、 阅读(538) 评论(0) 推荐(0)
摘要:题目链接http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1412大致题意:按照题目给出的几个正方形拼成一个矩形,每个小正方形中间有个管子,问拼成的矩形有多少个能通的管子。思路:dfs#include<stdio.h>#include<string.h>#define I (i*3)#define J (j*3)char str[51][51];int map[159][159];int n, m;int dir[4][2] = { {0, 1}, {0, -1}, {-1, 0}, {1, 0}};v 阅读全文
posted @ 2012-11-02 23:22 小猴子、 阅读(303) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<string.h>#define INF 0xfffffffstruct point { int x; int y;};int step[301][301];struct point que[30000001];int main(){ struct point p1, p2; while(scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y) != EOF) {// memset(step, 0, sizeof(step)); 阅读全文
posted @ 2012-10-31 23:36 小猴子、 阅读(391) 评论(2) 推荐(0)
摘要:题目连接;http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1179#include<stdio.h>#include<string.h>int a[101][101];int visited[101][101];int n, m;int dfs(int i, int j){ if( visited[i][j] ) return visited[i][j]; int sum = 0; if(i - 1 >= 0 && a[i][j] &g 阅读全文
posted @ 2012-10-31 23:34 小猴子、 阅读(341) 评论(0) 推荐(0)
摘要:题目连接http://poj.org/problem?id=1562大致题意:给出一个图找出一共多少块油田。油田用‘@’表示,与它相邻的8个区域如果还有油田‘@’则视为一块。#include<stdio.h>char grid[101][101];int n, m;int dir[8][2] = { {-1, -1}, {-1, 0}, {-1, 1}, { 0, 1}, { 1, 1}, { 1, 0}, { 1, -1}, { 0, -1}};void dfs(int x, int y){ int a, b; grid[x][y] = '*'; for(int 阅读全文
posted @ 2012-10-31 20:59 小猴子、 阅读(342) 评论(0) 推荐(0)
摘要:题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1110大致题意:第一行n,m,t代表n行m列的图,t是门开的时间,门开不超过1s。接下来n行m列的图。'.'代表通路'X'代表墙'S'代表初始位置'D'代表门的位置要求必须在t秒钟从S到达D,能到输出YES,否则输出NO。#include<stdio.h>char gird[8][8];int n, m, t, ans, a1, b1;void dfs(int i, int j, int k 阅读全文
posted @ 2012-10-31 20:11 小猴子、 阅读(259) 评论(0) 推荐(0)
摘要:View Code #include<stdio.h>#include<string.h>#include<limits.h>const int INF = INT_MAX;int que[10000000];int mem[10000000];int main(){ int f, s, g, u, d; while(scanf("%d %d %d %d %d", &f, &s, &g, &u, &d) != EOF) { int *fr = que, *ta = que; for(int i = 阅读全文
posted @ 2012-07-30 14:09 小猴子、 阅读(638) 评论(0) 推荐(0)