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

网站友情链接如何做/网站广告策划

网站友情链接如何做,网站广告策划,wordpress首页乱码,网站制作公司网站建设题目链接:http://acm.hdu.edu.cn/showproblem.php?pid1241 题目的意思很简单,问你有多少块油田。。‘’表示油田,‘*’表示不是油田。。连在一起的油田属于同一个油田。。八个方向相邻被称为连在一起。。 直接bfs或dfs都行。。时间复杂度为…

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1241

题目的意思很简单,问你有多少块油田。。‘@’表示油田,‘*’表示不是油田。。连在一起的油田属于同一个油田。。八个方向相邻被称为连在一起。。

直接bfs或dfs都行。。时间复杂度为O(m)。m为‘@’个数。。

分别用dfs和bfs实现了一下。。时间差不多。。原因吗?都是走过以后就不用在走了。。

bfs Code:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;const int N = 1e2 + 5;
const int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dy[] = {1, -1, -1, 0, 1, -1, 0, 1};
int n, m;
char map[N][N];struct Node
{int x, y;Node() {}Node(int a, int b){x = a;y = b;}
};void bfs(int bx, int by)
{queue<Node> q;q.push(Node(bx, by));map[bx][by] = '*';while(!q.empty()){Node tmp = q.front(), tmp1;q.pop();for(int i = 0 ; i < 8; i ++){tmp1.x = tmp.x + dx[i]; tmp1.y = tmp.y + dy[i];if(tmp1.x < 1 || tmp1.x > n || tmp1.y < 1 || tmp1.y > m || map[tmp1.x][tmp1.y] == '*') continue;q.push(tmp1);map[tmp1.x][tmp1.y] = '*';}}return ;
}int main()
{while(scanf("%d %d", &n, &m) && (n || m)){getchar();for(int i = 1; i <= n; i ++){for(int j = 1; j <= m; j ++)scanf("%c", &map[i][j]);getchar();}int ans = 0;for(int i = 1; i <= n; i ++){for(int j = 1; j <= m; j ++)if(map[i][j] == '@') {bfs(i, j); ans ++;}}cout << ans << endl;}return 0;
}


dfs Code:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;const int N = 105;
const int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dy[] = {1, -1, -1, 0, 1, -1, 0, 1};
char map[N][N];
int n, m;void dfs(int x, int y)
{
//    cout << "now = " << x << ' ' << y << endl;for(int i = 0; i < 8; i ++){int gox = x + dx[i], goy = y + dy[i];if(gox < 1 || gox > n || goy < 1 || goy > m || map[gox][goy] == '*') continue;map[gox][goy] = '*';dfs(gox, goy);}return ;
}int main()
{
//    freopen("1.txt", "r", stdin);while(scanf("%d %d", &n, &m) && (n || m)){getchar();for(int i = 1;  i <= n; i ++){for(int j = 1; j <= m; j ++)scanf("%c", &map[i][j]);getchar();}int ans = 0;for(int i = 1; i <= n; i ++){for(int j = 1; j <= m; j ++){if(map[i][j] == '@'){map[i][j] = '*';dfs(i, j);ans ++;}}}cout << ans << endl;}return 0;
}

dfs还是比较好玩的。。

http://www.lbrq.cn/news/1591741.html

相关文章:

  • 网站制作多少钱资讯/seo整站优化哪家好
  • 学校资源门户网站建设方案/南京网络营销服务
  • 东莞社保官方网站/岳阳seo公司
  • 做网站起诉/网销怎么找客户资源
  • 网站建设小程序湖南/十大接单平台
  • 建设银网站/站长工具使用方法
  • 做网站主机要求/网站底部友情链接代码
  • 沧州网络公司科技/seowhy官网
  • 北京电商购物网站开发/郑州网站开发公司
  • 深圳H5网站开发/百度竞价推广关键词优化
  • 南宁做棋牌网站的公司/软文写作技巧
  • 苹果做ppt模板下载网站有哪些/正规网络推广服务
  • 网站页面怎么做的好看/seo课程培训班费用
  • 网站怎么做短信营销/网络营销系统
  • 成都网站建设zmcms/seo网站快排
  • 网站右键禁止/谷歌推广怎么做
  • 南昌网站建设模板下载网址/抖音企业推广
  • 网站建设外包价格/百度手机快速排名点击软件
  • 广州做网站 timhi/网络营销平台的主要功能
  • 上传到网站/苏州企业网站关键词优化
  • 建设路第3小学网站电话/贴吧推广400一个月
  • 怎么创建公司网站空间/运用搜索引擎营销的案例
  • 专业的微网站哪家好/快速网站排名提升工具
  • 广州易网外贸网站建设/最近三天的新闻大事国内
  • 虚拟网站建设/企业网站建设公司
  • 网站开发需要用到哪些软件有哪些/营业推广方式
  • 营销型网站设计特点/太原网站建设优化
  • 做购物网站哪家公司好/北京seo收费
  • mac做网站/商业计划书
  • 网络文化经营许可证申请/seo外链友情链接
  • JavaScript 基础语法
  • DNS 服务器
  • C++ 变量初始化方式总结 | 拷贝初始化 | 列表初始化 | 值初始化
  • AWS EKS节点扩容时NLB与Ingress的故障处理与优化方案
  • 从exec到Shell:深度解析Linux进程等待,程序替换与自主Shell实现
  • 思途JSP学习 0802(项目完整流程)