(寒假集训)Cow Art(bfs)
Cow Art
时间限制: 1 Sec 内存限制: 64 MB
提交: 13 解决: 10
[提交][状态][讨论版]
题目描述
little known fact about cows is the fact that they are red-green
colorblind, meaning that red and green look identical to them. This
makes it especially difficult to design artwork that is appealing to
cows as well as humans.
Consider a square painting that is
described by an N x N grid of characters (1 <= N <= 100), each one
either R (red), G (green), or B (blue). A painting is interesting if
it has many colored "regions" that can be distinguished from
each-other. Two characters belong to the same region if they are
directly adjacent (east, west, north, or south), and if they are
indistinguishable in color. For example, the painting
RRRBB
GGBBB
BBBRR
BBRRR
RRRRR
has 4 regions (2 red, 1 blue, and 1 green) if viewed by a human, but only 3 regions (2 red-green, 1 blue) if viewed by a cow.
Given a painting as input, please help compute the number of regions in the painting when viewed by a human and by a cow.
输入
* Lines 2..1+N: Each line contains a string with N characters,describing one row of a painting.
输出
样例输入
5
RRRBB
GGBBB
BBBRR
BBRRR
RRRRR
样例输出
4 3
【分析】水题,两次BFS。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#define MAXN 111111
#define MAXM 222222
#define INF 1000000000
using namespace std;
const int N=1e2+;
int cnt,rt,n;
int vis[N][N];
int d[][]={,,,,-,,,-};
char str[N][N];
struct man{
int x,y;
};
void bfs(int x,int y){
man s;s.x=x;s.y=y;
queue<man>q;
q.push(s);
vis[x][y]=;
while(!q.empty()){
man t=q.front();
q.pop();
for(int i=;i<;i++){
int xx=t.x+d[i][];
int yy=t.y+d[i][];
if(xx>=&&xx<n&&yy>=&&yy<=n&&!vis[xx][yy]&&str[xx][yy]==str[t.x][t.y]){
man k;k.x=xx;k.y=yy;
q.push(k);
vis[xx][yy]=;
}
}
}
}
int main(){
scanf("%d",&n);
int ans1=,ans2=;
for(int i=;i<n;i++)scanf("%s",str[i]);
for(int i=;i<n;i++){
for(int j=;j<n;j++)
if(!vis[i][j]){
bfs(i,j);
ans1++;
}
}
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(str[i][j]=='R')str[i][j]='G';
}
}
memset(vis,,sizeof(vis));
for(int i=;i<n;i++){
for(int j=;j<n;j++)
if(!vis[i][j]){
bfs(i,j);
ans2++;
}
}
printf("%d %d\n",ans1,ans2);
return ;
}
(寒假集训)Cow Art(bfs)的更多相关文章
- CSU-ACM寒假集训选拔-入门题
CSU-ACM寒假集训选拔-入门题 仅选择部分有价值的题 J(2165): 时间旅行 Description 假设 Bobo 位于时间轴(数轴)上 t0 点,他要使用时间机器回到区间 (0, h] 中 ...
- (寒假集训) Cow Jog(二分优化的最长上升子数列)
Cow Jog 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 5[提交][状态][讨论版] 题目描述 Farmer John's N cows (1 <= N < ...
- POJ 3278 Catch That Cow(bfs)
传送门 Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 80273 Accepted: 25 ...
- HDU 2717 Catch That Cow (bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 Catch That Cow Time Limit: 5000/2000 MS (Java/Ot ...
- HDU 2717 Catch That Cow(BFS)
Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...
- hdoj 2717 Catch That Cow【bfs】
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Catch That Cow(BFS)
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- ***参考Catch That Cow(BFS)
Catch That Cow Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tot ...
- Catch That Cow (bfs)
Catch That Cow bfs代码 #include<cstdio> #include<cstring> #include<algorithm> #inclu ...
随机推荐
- python selenium 练习 自动获取豆瓣阅读当前特价书籍 chrome 元素定位 窗口切换 元素过期
豆瓣原创电子书每周推出数十本限时免费数目,一周免费期过后恢复原价.想着豆瓣原创书中有不少值得一看,便写了个脚本,免去一个个添加的烦恼. 使用了Windows下selenium+Python的组合,有较 ...
- Python代码书写规范
Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不要使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在 ...
- Leetcode 668.乘法表中第k小的数
乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 1: 输入 ...
- NodeJs02 美女爬虫
note: demo代码要编号 导出模块 一个js文件就是一个模块,模块内部的所有变量,对象,方法对外界都不可见.如果想暴漏出去让别人用,就需要导出模块.语法如下: module.exports = ...
- 团队项目-第一次Scrum 会议
时间:10.23 时长:30分钟 地点:F楼2层沙发休息处 工作情况 团队成员 已完成任务 待完成任务 解小锐 学习使用cocos creator 学习官方样例 陈鑫 学习JavaScript 学习c ...
- ESLint 代码检查规范
目录 Airbnb Javascript Style Guide 引用 对象 数组 函数 箭头函数 类和构造器 模块 Iterators and Generators 变量 比较运算符 注释 空格 A ...
- Git 提交修改
今天发现前几天的某一个提交因为忽略文件的问题而导致有几个文件没有提交,需要修改一下某个提交,研究一下可以用rebase命令来完成,执行过程模拟如下: 1. 环境搭建,版本库如下: 文件目录如下: 假设 ...
- 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)
A.The game of Osho(sg函数+二项展开) 题意: 一共有G个子游戏,一个子游戏有Bi, Ni两个数字.两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输.问 ...
- 在浏览器中进行深度学习:TensorFlow.js (八)生成对抗网络 (GAN
Generative Adversarial Network 是深度学习中非常有趣的一种方法.GAN最早源自Ian Goodfellow的这篇论文.LeCun对GAN给出了极高的评价: “There ...
- Codeforces Round #504:D. Array Restoration
D. Array Restoration 题目链接:https://codeforces.com/contest/1023/problem/D 题意: 给出一个序列,现在要求对一个全为0的序列执行q次 ...