【BFS】coj 1102 Region of Interest
来源:互联网 发布:大数据公司 编辑:程序博客网 时间:2024/05/20 23:30
Region of Interest
Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: lld
Java class name:Main
在一幅遥感图像上,分布着N个湖泊(N<=10),小明想通过计算机知道,其中一个或多个湖泊的面积和,他的做法如下:1、在他想计算的湖泊上,每个湖泊各取一个特征点(在计算机中用像素表示)
2、在遥感图像上,把在所选点周围,属性和该点一样的其他像素点也选上,所有被选中的点的总和就是湖泊的面积。
现在,我们用一个二维字符数组来代替遥感图像(如样例所示),图像中,每个点的属性就是字符的值:湖泊用L表示,其他地物用S来表示,湖泊中,选取了的特征点用T表示,特征点也属于湖的一部分。
然后,请你计算所选中的湖泊面积(用点的和来表示)。
Input
第一行:遥感图像的行、列数m、n
其中m和n是不超过30的正整数
第二行:m行n列的二维字符数组,表示遥感图像,湖泊用L表示,其他地物用S来表示,湖泊中,选取了的特征点用T表示。
注意:需要计算的湖泊个数可以是一个,也可以是多个,而一个湖泊只放一个特征点
其中m和n是不超过30的正整数
第二行:m行n列的二维字符数组,表示遥感图像,湖泊用L表示,其他地物用S来表示,湖泊中,选取了的特征点用T表示。
注意:需要计算的湖泊个数可以是一个,也可以是多个,而一个湖泊只放一个特征点
Output
所求的,湖泊总面积,一个整数
Sample Input
10 10SSSSSSSSSSSLLLSSSSSSSLTLSSSSSSSSSSSSSSSSLLLLLLSSSSLLLSSSSSTSSSSSSSSSSSSSSSLLLLLSSSSSSLLTLSSSSSSLLLLS
Sample Output
20///AC代码#include <iostream>#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <algorithm>#include <functional>#define PI acos(-1)#define eps 1e-8#define inf 0x3f3f3f3f#define debug(x) cout<<"---"<<x<<"---"<<endltypedef long long ll;using namespace std;int m, n;char str[35][35];bool vis[35][35];struct node{ int x, y;};int dix[4] = {1, -1, 0, 0};int diy[4] = {0, 0, 1, -1};int cango(int x, int y){ return x >= 0 && x < m && y >= 0 && y < n && vis[x][y] == false;}int bfs(int x, int y){ queue<node> qu; node gg; gg.x = x; gg.y = y; qu.push(gg); memset(vis, false, sizeof(vis)); vis[x][y] = true; int sum = 0; while (!qu.empty()) { gg = qu.front(); qu.pop(); sum++; for (int i = 0; i < 4; i++) { int _x = gg.x + dix[i]; int _y = gg.y + diy[i]; if (cango(_x, _y) && str[_x][_y] == 'L') { node hh; hh.x = _x; hh.y = _y; qu.push(hh); vis[_x][_y] = true; } } } return sum;}int main(){ while (cin >> m >> n) { int ans = 0; for (int i = 0; i < m; i++) { cin >> str[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (str[i][j] == 'T') { ans += bfs(i, j); } } } cout << ans << endl; } return 0;}
阅读全文
0 0
- 【BFS】coj 1102 Region of Interest
- halcon--Region Of Interest
- OpenCV Region of Interest (ROI)
- halcon-ROI(region of interest)
- gem5 parsec2.1 Region of Interest explations
- 【Opencv 学习笔记】 -- ROI(Region of Interest)
- ROI/Region of Interest感兴趣区域
- Open CV 学习开发笔记之ROI(Region Of Interest)感兴趣区域(三)
- Matlab图像处理(一):二值化、开操作、连通区域提取、重心,ROI(region of interest)
- Area of Interest
- AOI( Area Of Interest )
- coj 1102
- coj 1102
- BFS——surrounded region
- Places of Interest - Guilin and Yang Shuo
- Courses of Interest to the SLMC group
- 【BFS】coj 1061 【魔方系列】最大色块
- 關於region Of interst-ROI
- DrawerLayout && NavigationView
- 虚拟机ubuntu 16.04 和 win7通过远程连接实现文件传递
- SpringMVC集成Swagger2,初尝试和遇到的相关问题
- mysql 一些常用命令
- 数据库ACID
- 【BFS】coj 1102 Region of Interest
- MySQL Innodb存储引擎学习笔记
- jdk环境变量的配置
- 教你操作 linux grep 指令,搜索内容或是汇出
- Spring官网下载jar包
- eclipse下切换svn用户 (换用户登录)
- 方块倒计时
- 湖南中医药大学2017年集训队第四场选拔赛-Problem D: Jug Hard
- 解决跨域问题