G. Sheba's Amoebas -ICPC North Central NA Contest 2017
https://nanti.jisuanke.com/t/43374



题意
判断像素矩阵中像素围成的封闭区域的个数
思路
对于每一个像素,检查周围是否有像素形成相连
从当前下一个未标记的像素开始进行搜索,搜索结果作为下一个节点进行搜索,在搜索的同时进行染色
遇到已经染色的像素,判断为一个封闭空间
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10; bool compare(int a, int b)
{
return a < b;//升序
} int filed[102][102] = {0};
bool Fill_Color(int x , int y)
{
bool flag = 0;
if(filed[x+1][y] == 1){
filed[x+1][y] = 2;
Fill_Color(x+1 , y);
flag = 1;
}
if(filed[x-1][y] == 1){
filed[x-1][y] = 2;
Fill_Color(x-1 , y);
flag = 1;
}
if(filed[x][y+1] == 1){
filed[x][y+1] = 2;
Fill_Color(x , y+1);
flag = 1;
}
if(filed[x][y-1] == 1){
filed[x][y-1] = 2;
Fill_Color(x , y-1);
flag = 1;
}
if(filed[x+1][y+1] == 1){
filed[x+1][y+1] = 2;
Fill_Color(x+1 , y+1);
flag = 1;
}
if(filed[x-1][y-1] == 1){
filed[x-1][y-1] = 2;
Fill_Color(x-1 , y-1);
flag = 1;
}
if(filed[x+1][y-1] == 1){
filed[x+1][y-1] = 2;
Fill_Color(x+1 , y-1);
flag = 1;
}
if(filed[x-1][y+1] == 1){
filed[x-1][y+1] = 2;
Fill_Color(x-1 , y+1);
flag = 1;
}
return flag;
}
char pool[100] = {0};
int main()
{
int a , b;
cin >>a >>b;
int counter = 0;
for(int i = 1;i<=a;i++)
{
cin >>pool;
for(int j = 0;j<=b;j++)
{
if(pool[j] == '#')
{
filed[i][j] = 1;
}
}
}
for(int i = 1;i<=a;i++)
{
for(int j = 0;j<=b;j++)
{
if(filed[i][j] == 1)
{
Fill_Color(i , j);
counter++;
}
}
}
cout<<counter;
}
G. Sheba's Amoebas -ICPC North Central NA Contest 2017的更多相关文章
- ICPC North Central NA Contest 2018
目录 ICPC North Central NA Contest 2018 1. 题目分析 2. 题解 A.Pokegene B.Maximum Subarrays C.Rational Ratio ...
- Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)
题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight ...
- Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)
A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...
- 2017-2018 ACM-ICPC East Central North America Regional Contest (ECNA 2017) Solution
A:Abstract Art 题意:给出n个多边形,求n个多边形分别的面积和,以及面积并 思路:模板 #include <bits/stdc++.h> using namespace st ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- The North American Invitational Programming Contest 2017 题目
NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black st ...
- 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解
题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...
- 组队练习赛(Regionals 2012, North America - East Central NA)
A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...
随机推荐
- .NET外挂系列:7. harmony在高级调试中的一些实战案例
一:背景 1. 讲故事 如果你读完前六篇,我相信你对 harmony 的简单使用应该是没什么问题了,现在你处于手拿锤子看谁都是钉子的情况,那这篇我就找高级调试里非常经典的 3个钉子 让大家捶一锤. 二 ...
- mp4文件下载,而不是在线播放
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- const关键字和指针
const指针 const关键字 1.const int p const int p 与 int const p 是等价的. 用const修饰变量 p 时,则 p 成为只读变量,必须在定义的同时初始化 ...
- 手摸手教你从生成CRD到编写自定义控制器
介绍 我们可以使用code-generator 以及controller-tools来进行代码自动生成,通过代码自动生成可以帮我们自动生成 CRD 资源对象,以及客户端访问的 ClientSet.In ...
- 使用ajax实现验证码
java后台的servlet: 1 @WebServlet(value = "/login.love",name = "AjaxLoginServlet") 2 ...
- Opencv学习:回到原点!关于一些基础的函数
opencv简单的图片读取和显示 1.图像读取 Mat img = imread("C:/clip.png", 1); imshow("fang2", img ...
- 如何在FastAPI中打造坚不可摧的安全防线?
title: 如何在FastAPI中打造坚不可摧的安全防线? date: 2025/06/20 11:33:15 updated: 2025/06/20 11:33:15 author: cmdrag ...
- 在x86的window安装arm64虚拟机
安装qemu msys2:官网 按照下图步骤下载文件并安装 打开下面终端 根据:qemu官网 在终端执行安装命令:pacman -S mingw-w64-ucrt-x86_64-qemu 下载系统镜像 ...
- Blazor学习之旅 (13) Razor类库的使用
在上一篇我们学习了Blazor和JavaScript的互操作性,这一篇我们了解下如何创建和使用Razor类库. 什么是Razor类库? 我们都知道,在.NET应用程序中,我们可以通过NuGet来安装各 ...
- C# 设置dll 别名
extern alias VideoFFMPEGX64;using VideoFFMPEGX64::Accord.Video.FFMPEG;