当前位置: 首页 > news >正文

网络营销策划课程手机优化管家

网络营销策划课程,手机优化管家,量个网站一个域名,用spl做网站题目&#xff1a; 样例&#xff1a; 输入 3 3 2 1 输出 3 2 1 0 -1 4 3 2 1 思路&#xff1a; 单纯的BFS走一遍即可&#xff0c;只是方向坐标的移动变化&#xff0c;需要变化一下。 代码详解如下&#xff1a; #include <iostream> #include <vector> #include…

题目:

样例:

输入
3 3 2 1
输出
3 2 1
0 -1 4
3 2 1

思路:

        单纯的BFS走一遍即可,只是方向坐标的移动变化,需要变化一下。

代码详解如下:

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define endl '\n'
#define x first
#define y second
#define mk make_pair
#define YES puts("YES")
#define NO puts("NO")
#define umap unordered_map
#define All(x) x.begin(),x.end()
#pragma GCC optimize(3,"Ofast","inline")
#define IOS std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0)
using namespace std;
const int N = 500;
using PII = pair<int,int>;
// 象棋走动的方向
int dx[8] = {2,2,-2,-2,1,-1,1,-1};
int dy[8] = {1,-1,1,-1,2,2,-2,-2};int g[N][N],n,m;	// 象棋棋盘以及大小
bool st[N][N];	// 标记是否走过当前坐标
PII now;	// 当前象棋坐标inline bool isRun(int &x,int &y)
{return (x > 0 && x <= n && y > 0 && y <= m && !st[x][y]);
}inline void BFS()
{// 初始化坐标所对应的最少步数memset(g,-1,sizeof g);g[now.x][now.y] = 0;	// 初始化起点步数为 0int step = 0;queue<PII>q;q.emplace(now);while(q.size()){int sz = q.size();while(sz--){PII tem = q.front();q.pop();	// 取出当前坐标st[tem.x][tem.y] = true;	// 标记当前坐标g[tem.x][tem.y] = step;	// 存储当前坐标所对应的最少步数// 尝试往各个方向坐标走动for(int i = 0;i < 8;++i){int bx = tem.x + dx[i];int by = tem.y + dy[i];if(isRun(bx,by)){// 如果符合走动条件// 存储下一个走动的坐标,并标记q.emplace(mk(bx,by));st[bx][by] = true;}}}++step;}
}// 打印棋盘各个坐标所对应的最少步数
inline void PrintG()
{for(int i = 1;i <= n;++i){for(int j = 1;j <= m;++j){if(j > 1) cout << ' ';	// 控制输入格式cout << g[i][j];}cout << endl;}
}inline void solve()
{cin >> n >> m >> now.x >> now.y;	// 输入所对应的信息BFS();	// BFS 搜索各个坐标所对应的最少步数PrintG();	// 输出答案
}int main()
{
//	freopen("a.txt", "r", stdin);IOS;int _t = 1;
//	cin >> _t;while (_t--){solve();}return 0;
}

最后提交:

http://www.dinnco.com/news/72742.html

相关文章:

  • 专业做毕业设计网站设计福州短视频seo机会
  • 虚拟主机免费试用seo常用的工具
  • 全运会网站建设方案宁波seo外包方案
  • 网站做竞价优化微信营销软件手机版
  • 电子商务网站建设技术怎样进行seo
  • 项目网上备案流程唐山seo优化
  • wordpress id乱码嘉兴seo外包公司费用
  • 祥云平台做网站好不好百度链接地址
  • 企业网站风格外链群发平台
  • 怎样做订房网站seo好seo
  • 简阳网站建设上海最新发布最新
  • 做简单网站的步骤最好的网络营销软件
  • 许昌网站开发哪家好百度站点
  • 做h5哪些网站好 知乎昆山网站建设
  • 广州门户网站开发株洲网站设计
  • 企业 网站 建设 规范湘潭网络推广
  • 一流的句容网站建设优化大师客服
  • 5网站开发山东百度推广代理商
  • 龙采科技做网站多少钱代写新闻稿
  • 网页设计基础开题报告及网页流程图求职seo
  • 利用模板做网站电商怎么做
  • html5网站制作台州做优化
  • 广州个人网站制作公司seo的特点是什么
  • 网站建设策划怎么沟通软文网站有哪些
  • 莱阳做网站seo排名的职位
  • 南通做网站公司无锡网络公司
  • 英文网站有哪些泉州seo排名扣费
  • 网站建设小图标青岛app开发公司
  • 修改 自豪地采用wordpress如何做seo
  • 网站开发word文档百度竞价托管哪家好