Codeforces 549A. Face Detection[模拟]
1 second
256 megabytes
standard input
standard output
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
In the single line print the number of faces on the image.
4 4
xxxx
xfax
xcex
xxxx
1
4 2
xx
cf
ae
xx
1
2 3
fac
cef
2
1 4
face
0
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:

In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:

In the fourth sample the image has no faces on it.
题意:四个格子里出现face四个字母
我是用了个vis数组,题解是给四个格子字母排序与acef对比
//
// main.cpp
// cf549a
//
// Created by Candy on 9/15/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=;
int n,m,ans=;
int a[N][N],vis[];
char s[N];
int main(int argc, const char * argv[]) {
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%s",s);
for(int j=;j<m;j++)
a[i][j+]=s[j]-'a';
} for(int i=;i<=n-;i++)
for(int j=;j<=m-;j++){
memset(vis,,sizeof(vis));
vis[a[i][j]]++;
vis[a[i+][j]]++;
vis[a[i][j+]]++;
vis[a[i+][j+]]++;
if(vis[]&&vis['f'-'a']&&vis['c'-'a']&&vis['e'-'a']) ans++;
}
printf("%d",ans);
return ;
}
Codeforces 549A. Face Detection[模拟]的更多相关文章
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- Codeforces 658A. Robbers' watch 模拟
A. Robbers' watch time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||
Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...
随机推荐
- Java2_JDK的安装和配置
什么是JDK JDK就是Java Development Kit,java开发工具包,由sun公司开发. JDK的三个版本 桌面系统或应用程序的标准版(Java 2 Platform Standard ...
- [DeviceOne开发]-轮播图和多模板的简单示例
一.简介 这个例子是利用Slideview组件实现循环轮播的效果,同时这个slideview作为一个listview的最上面的一行数, 1. listview有2个模板,一个是以slideview为核 ...
- (转)JavaScript-性能优化之函数节流(throttle)与函数去抖(debounce)
JavaScript-性能优化之函数节流(throttle)与函数去抖(debounce) 函数节流,简单地讲,就是让一个函数无法在很短的时间间隔内连续调用,只有当上一次函数执行后过 ...
- HTML <select> 标签 创建单选或多选菜单
所有主流浏览器都支持 <select> 标签. select 元素可创建单选或多选菜单. <select&> 元素中的 <option> 标签用于定义列表中 ...
- 获取设备的mac地址可靠的方法
参考自:http://www.open-open.com/lib/view/open1433406847322.html /** * 获取设备的mac地址 * * @param ac * @param ...
- android Activity runOnUiThread() 方法使用
在android 中我们一般用 Handler 做主线程 和 子线程 之间的通信 . 现在有了一种更为简洁的写法,就是 Activity 里面的 runOnUiThread( Runnable )方法 ...
- 你真的了解UITextField吗?
一:首先查看一下关于UITextField的定义 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextField : UIControl <UITextIn ...
- TCP连接状态与2MSL等待时间
1 连接状态图 2 建立连接:三次握手,不使用DNS和使用DNS 3 关闭连接-四次握手 连接双方任何一方调用close()后,连接的两个传输方向都关闭,不能再发送数据了.如果一方调用shutdown ...
- 使用windows服务更新站点地图
由于公司平台访问人数逐渐增多,公司项目的数据库已经几次出现宕机现象.为减轻数据库压力,我上个月对公司项目做了下调整.把新闻板块提取出来单独一个站点,单独一个数据库.减少了主站点和数据库的负担和压力. ...
- win10_x64更新错误解决: 安装一些更新时出现问题,但我们稍后会重试。如果持续出现这些问题,并且你想要搜索Web或联系支持人员以获取相关信息,以下信息可能会对你有帮助:
可能的原因: 1.windows 服务没打开 win+r,打开[运行]对话框 输入 [service.msc] 找到 [Windows Firewall]和[Internet connection s ...