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

深圳外贸seo网站推广南城网络公司

深圳外贸seo网站推广,南城网络公司,功能分类模块类型网站,网站备案收费题目&#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.yayakq.cn/news/865249/

相关文章:

  • 网站建设行业广告语海南高端网站建设定制
  • 黑龙江哈尔滨网站建设成都建好的网站出租
  • 各大网站提交入口深圳建站工作室
  • 网站后台怎么上传图片产品如何用wordpress做网站
  • 用jquery做网站做简历最好的网站
  • 大连嘉良建设有限公司网站好看的404页面html
  • 安全网站建设与服务的关系建设银行网站公告在哪
  • 织梦可以做论坛网站河南新闻头条最新消息
  • 网站建设立项申请书郑州建设工程信息网官网首页
  • 做网站用php还是node手机网站全屏代码
  • 怎样让百度搜索到自己的网站模板网站制作怎么样
  • 正规的培训行业网站开发网站功能需求说明
  • 公司网站与营销网站在栏目上的不同品牌运营
  • 专业做ea的网站荆州 网站建设
  • 门户wordpress主题下载深圳seo网站建设
  • 深圳网站建设公司排行榜企业网站建设费用大约多少钱
  • html格式网站媒体网站推进信息化建设
  • 网站页面设计需求wordpress 提示插件
  • 做站群网站会被k吗站内seo怎么做
  • 简单易做的网站河南做网站公司排名
  • 做网站的域名怎么申请wordpress音乐播放器插件
  • 正规的环保行业网站开发c 可以做网站吗
  • php网站开发账号密码网站建设公司渠道
  • 用摄像头直播网站怎么做注册海外公司
  • 湖北网站建设搭建wordpress默认主题12
  • 个人主页网站建设潍坊住房公积金官网登录
  • 湘潭响塘乡建设局网站wordpress激活码
  • 中小企业建网站吉林网站建设价格
  • 门户网站建设方案 模板wordpress回复微信查看
  • 番禺手机网站制作推广企业信息公示系统官网