全是套路——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) 次礼物. 每次发放,会给出三个参 ...
随机推荐
- Entity Framework 学习笔记
1.自定义数据库链接字符串上下文 public class PetDbContext : DbContext { public PetDbContext() : base("name=Dem ...
- VM12.1.1 下载 序列号
VF5XA-FNDDJ-085GZ-4NXZ9-N20E6UC5MR-8NE16-H81WY-R7QGV-QG2D8ZG1WH-ATY96-H80QP-X7PEX-Y30V4AA3E0-0VDE1-0 ...
- Android 常用控件的介绍
http://www.cnblogs.com/linjiqin/category/284058.html 最流行的android组件大全:http://www.cnblogs.com/linjiqin ...
- 转:C# 中 MSCHART 饼状图显示百分比
转自:http://blog.sina.com.cn/s/blog_51beaf0e0100yffo.html 1)显示百分比 Chart1.Series["Series1"].L ...
- spring mvc使用@InitBinder 标签对表单数据绑定
在SpringMVC中,bean中定义了Date,double等类型,如果没有做任何处理的话,日期以及double都无法绑定. 解决的办法就是使用spring mvc提供的@InitBinder标签 ...
- Java的常用对象①②
Java的常用对象① Java的常用对象有很多,这里只对lang包中常用的Object,Date(Calendar,DateFormat,Math),System,Runtime进行介绍.㈠Objec ...
- C++注意
断言assert是仅在Debug版本起作用的宏,它用于检查“不应该”发生的情况. 在函数的入口处,使用断言检查参数的有效性(合法性). 如果程序在assert处终止了,并不是说含有该assert的函数 ...
- javaEE中关于dao层和services层的理解
javaEE中关于dao层和services层的理解 入职已经一个多月了,作为刚毕业的新人,除了熟悉公司的项目,学习公司的框架,了解项目的一些业务逻辑之外,也就在没学到什么:因为刚入职, 带我的那个师 ...
- 如何在IDEA上创建Spring MVC项目
对于刚刚从eclipse.myeclipse转到IDEA工具,在搭建项目遇到了一些问题,所以让我来分享我的搭建过程. 建议大家准备java环境.IDEA工具.tomcat.maven了,还有我是win ...
- 简单三个表之间关联 与 case when语句的应用
select p.conttract_id,l.order_code,jz.cur_branch from wy_auto_workflow_log l,wg_pjhsb p,wg_jzmb jz w ...