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的更多相关文章

  1. ICPC North Central NA Contest 2018

    目录 ICPC North Central NA Contest 2018 1. 题目分析 2. 题解 A.Pokegene B.Maximum Subarrays C.Rational Ratio ...

  2. 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 ...

  3. Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

    A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...

  4. 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 ...

  5. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  6. 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 ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  8. The North American Invitational Programming Contest 2017 题目

    NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K   A mysterious circular arrangement of black st ...

  9. 2018 ICPC Pacific Northwest Regional Contest I-Inversions 题解

    题目链接: 2018 ICPC Pacific Northwest Regional Contest - I-Inversions 题意 给出一个长度为\(n\)的序列,其中的数字介于0-k之间,为0 ...

  10. 组队练习赛(Regionals 2012, North America - East Central NA)

    A.Babs' Box Boutique 给定n个盒子,每个盒子都有长宽高(任意两个盒子长宽高不完全相同),现在选盒子的任意两面,要求x1 <= x2 && y1 <= y ...

随机推荐

  1. Java面试|BIO、NIO、AIO的区别和应用场景

    摘要:BIO是一个连接一个线程,NIO是一个请求一个线程,AIO是一个有效请求一个线程.   在学习Java I/O类库时,容易混淆NIO.BIO.AIO这几个概念,同时对于阻塞和非阻塞.同步和异步的 ...

  2. 注解@Transactional事务失效的常见场景

    在<Spring Boot事务管理>中,小编介绍了注解@Transactional的基本属性和使用方法,这里介绍事务失效的八种场景,使大家对注解@Transactional有一个更深刻的认 ...

  3. Js RSA非对称加密

    // RSA 加密 async function encryptData(publicKeyStr, data) { const publicKey = await importPublicKey(p ...

  4. K8s集群中的DNS服务(CoreDNS)详解

    概述 官网文档:https://kubernetes.io/zh-cn/docs/concepts/services-networking/dns-pod-service/ 在 Kubernetes( ...

  5. 爬取西刺代理的IP与端口(一)

    0x01 简陋代码是,获取(.*?)的字符串 #coding:utf-8 from requests import * import re headers = { "accept" ...

  6. MyBatisPlus笔记(高级)

    MyBatisPlus(高级) 作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 目录 MyBatisPlus(高级) 说明: 相关连接: 慕课入门视频: 入门文章: 本文对应进阶视频: 整合的gi ...

  7. 从排查ip不合法,到发现自己拖延,自欺的问题

    现象: 我调用推送接口,接口提示 ip地址不合法,服务器调用的接口ip需要在第三方平台上设置,调用提示 ip 错误 我将自己的出口ip地址配置到了第三方平台上,出口ip地址可以通过在服务器上面执行 c ...

  8. 2-Tensorboard使用

    1. Tensorboard用途 ① Tensorboad 可以用来查看loss是否按照我们预想的变化,或者查看训练到某一步输出的图像是什么样. pip install tensorboard Req ...

  9. 超赞!本地程序调用云知识库实现RAG功能

    在 Spring AI Alibaba 程序中,我们可以直接使用本地程序调用百炼平台的云知识库,实现知识库文档解析.分块.向量化存储等一条龙服务. 这样,开发者就不用本地部署搭建向量数据库.不用进行复 ...

  10. 破解五大运营痛点:盘古信息IMS MOM重塑PCB工厂数字化基石

    随着5G.物联网等技术发展,PCB行业下游消费电子.汽车电子等领域需求呈现小批量多品种.高精度高可靠性.快速交付特点.传统"规模驱动"生产模式难以适应新需求,行业竞争焦点转向质量. ...