全是套路——BFS
#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <math.h>
#include <limits.h>
#include <set>
#include <memory>
#include <queue> using namespace std; struct point{
int x;
int y;
point *parent;
int step;
}; int map[][] = { , , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , ,
, , , , , , , , , }; vector<point> p;
int BFS(point s,point e)
{
queue<point> q;
q.push(s);
while (!q.empty())
{
point start = q.front();
point *s1 = new point; s1->x = start.x; s1->y = start.y; s1->parent = start.parent;
q.pop();
if (start.x == e.x&&start.y == e.y)
{
p.push_back(start);
return start.step;
}
if (map[start.x + ][start.y] != && start.x + <= && start.x + >= )
{
point tmp = { start.x + , start.y, s1, start.step + };
map[start.x + ][start.y] = ;
q.push(tmp);
}
if (map[start.x - ][start.y] != && start.x - <= && start.x - >= )
{
point tmp = { start.x - , start.y, s1, start.step + };
map[start.x - ][start.y] = ;
q.push(tmp);
}
if (map[start.x][start.y + ] != && start.y + <= && start.y + >= )
{
point tmp = { start.x, start.y + , s1, start.step + };
map[start.x][start.y + ] = ;
q.push(tmp);
}
if (map[start.x][start.y - ] != && start.y - <= && start.y - >= )
{
point tmp = { start.x, start.y - , s1, start.step + };
map[start.x][start.y - ] = ;
q.push(tmp);
}
start.step++;
} } int main()
{
point s = { , }, e = { , };
BFS(s, e);
char p1[] = "abcd", *p2 = "ABCD", str[] = "xyz";
strcpy(str + , strcat(p1 + , p2 + ));
printf("%s", str);
point *point = &p[];
while (point->parent != NULL)
{
cout << point->x << " " << point->y << endl;
point = point->parent;
}
return ;
}
全是套路——BFS的更多相关文章
- 【HDU - 2102】A计划(bfs)
-->A计划 Descriptions: 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的 ...
- 一些关于Linux入侵应急响应的碎碎念
近半年做了很多应急响应项目,针对黑客入侵.但疲于没有时间来总结一些常用的东西,寄希望用这篇博文分享一些安全工程师在处理应急响应时常见的套路,因为方面众多可能有些杂碎. 个人认为入侵响应的核心无外乎四个 ...
- CH模拟赛 皇后游戏
/* 做的时候手推了一下n=2的四种情况,再排一下序就可以了,证明不是很严谨,但我想这就行了,毕竟全是套路 */ #include<iostream> #include<cstdio ...
- 十连测Day1 题解
A. 奥义商店 有一个商店,n个物品,每个物品有一个价格和一种颜色. 有m个操作,操作有两种,一种是修改一个位置的价格,另一种是购买,每次购买指定一个公差d和一个位置k,找到包含这个位置k公差为d的同 ...
- elasticsearch-PHP第一天
遇到很大的问题就是,给边做边找原因,看官方文档,全英文看不懂.只能慢慢一步一步去做. 性子太急,真的不行,跨越性太大,卡一个小时多,才发现,连安装都没搞明白. 首先需要一个JAVA环境,上百度 ...
- Spring AOP (Spring 3.x 企业应用开发实战读书笔记第六章)
从面相对象编程到面相切面编程,是一种代码组织方式的进化. 每一代的代码组织方式,其实是为了解决当时面对的问题.比如写编译器和写操作系统的时候的年代当然要pop,比如写界面的时候当然要oop,因为界面这 ...
- android MessageQueue入门
接触安卓几年了.但是感觉一直不是很明白,东西太多了.反过来说就是自己太菜了.很多东西其实都是模凌两可,不熟悉,很多知识点都是知道一点,最多大家都这样用.没问题,事件长了也一直这样用的.但是有个问题,安 ...
- ZJOI2019Day2AFO记
题目读下来感觉,,,怎么看上去模型都这么简单全是套路题的样子.先想了下T3应该会50,是个计算几何,50够了..于是先写了40(10分等下再来写)这样就花掉了一个小时.....过去看T1,直接高斯消元 ...
- 洛谷T21778 过年
题目描述 有 n(1 \leq n \leq 10^5)n(1≤n≤105) 个小朋友,过年了,要发放 m(1 \leq m \leq 10^5)m(1≤m≤105) 次礼物. 每次发放,会给出三个参 ...
随机推荐
- LeetCode 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- 培训第五天---JS
&&与||的基础<script type="text/javascript"> var c = 4||3; alert(c);</script&g ...
- 转(Response.WriteFile 无法下载大文件解决方法)
以前用Response.WriteFile(filename),但当遇到大文件时无法完整下载. 该方法最大的问题,它不是直接将数据抛到客户端,而是在服务器端(IIS)上缓存.当下载文件比较大时,服务器 ...
- AE IRasterCursor 改变栅格图层像素值
1 public void ChangePixelValue(double xMax, double xMin, double yMax, double yMin,double[,] PixelCha ...
- live555+ffmpeg如何提取关键帧(I帧,P帧,B帧)
live555+ffmpeg如何提取关键帧(I帧,P帧,B帧)开发流媒体播放器的时候,特别是在windows mobile,symbian(S60)平台开发时,很可能遇到需要自己开发播放器的情况.S ...
- 在CentOS或RHEL防火墙上开启端口
转载自:https://linux.cn/article-4243-1.html 如果希望在服务器上提供服务,诸如CentOS或RHEL的企业级Linux发行版包含内置的强大防火墙,它们默认的防火墙规 ...
- Loadrunner---解决乱码问题
在使用Loadrunner录制和回放时有时候会因为乱码问题报错,且让我们很难定位出脚本问题所在.此事我们做一下分析loadrunner为什么会出现乱码这种情况呢? 1.乱码产生的原因 1)loadru ...
- 【Python】supervisor安装和管理celery
参考:http://blog.csdn.net/wawa8899/article/details/52743861 参考:http://www.cnblogs.com/mountaingeek/p/5 ...
- webApi上传下载文件
上传文件通过webApi html端调用时包含(form提交包含 enctype="multipart/form-data",才可以启作用获取到文件) public class U ...
- 排序算法(JAVA)
import java.util.Random; /** * 排序测试类 * * 排序算法的分类如下: * 1.插入排序(直接插入排序.折半插入排序.希尔排序): * 2.交换排 ...