Looksery Cup 2015——AFace Detection

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.

Input

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.

Output

In the single line print the number of faces on the image.

Sample test(s)

input

4 4xxxxxfaxxcexxxxx

output

1

input

4 2xxcfaexx

output

1

input

2 3faccef

output

2

input

1 4face

output

0

Note

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.

#include<cstdio>
#include<cstring>
#include<algorithm>
int main()
{
	int n,m;
	int c[55][55];
	char  a[55][55];
	while(~scanf("%d%d",&n,&m)){
		int count = 0;
		memset(c,0,sizeof(c));
		getchar();
		for(int i = 1; i <= n ; i++){
			for(int j = 1; j <= m ; j++)
				scanf("%c",&a[i][j]);
			getchar();
		}
	    for(int i = 1; i <= n ; i++){
			for(int j = 1; j <= m ; j++){
				if(a[i][j] == ‘f‘)
					c[i][j] = 1;
				if(a[i][j] == ‘a‘)
					c[i][j] = 10;
				if(a[i][j] == ‘c‘)
					c[i][j] = 100;
				if(a[i][j] == ‘e‘)
					c[i][j] = 1000;
			}
		}
//		for(int i = 1; i <= n ; i++){
//			for(int j = 1; j <= m ; j++){
//				printf("%c",a[i][j]);
//			}
//			puts("");
//		}
//		for(int i = 1; i <= n; i++){
//			for(int j = 1; j <= m ;j++)
//				printf("%d",c[i][j]);
//		puts("");
//	}
		for(int i = 1; i < n ; i++){
			for(int j = 1; j < m ;j++){
				if(c[i][j] + c[i+1][j+1] + c[i+1][j] + c[i][j+1] == 1111)
					count++;
					}
		}
		printf("%d\n",count);
	}
	return 0;
}

  

时间: 2024-11-10 00:52:28

Looksery Cup 2015——AFace Detection的相关文章

Looksery Cup 2015 Editorial

下面是题解,做的不好.下一步的目标是rating涨到 1800,没打过几次cf A. Face Detection Author: Monyura One should iterate through each 2x2 square and check if it is possible to rearrange letters in such way they they form the word "face". It could be done i.e. by sorting al

codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱

#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <iostream> using namespace std; bool fun(double l1,double r1,double l2,double r2){ return (l1 <= r2 && l1

codeforces Looksery Cup 2015 H Degenerate Matrix

The determinant of a matrix 2?×?2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any

codeforces Looksery Cup 2015 D. Haar Features

The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model

codeforces #549 Looksery Cup 部分题解

掉Rating快乐~~ A.Face Detection 题目大意:给定一个n?m的矩阵,求有多少2?2的子矩形满足单词"face"的每个字母在矩形中恰好出现一次 签到题 #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 55 using namespace std; int n,m,ans; char map[M

hacker cup 2015 Round 1 解题报告

A:求区间内素因子个数等于n的数有多少个 解题思路:筛法 解题代码: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年01月18日 星期日 13时54分20秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include&

hacker cup 2015 资格赛

A:交换一个数的两位,问能得到最大和最小的数是多少. 水题: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2015年01月10日 星期六 17时16分44秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<s

Codeforces VK Cup 2015 Wild Card Round 1 (AB)

比赛链接:http://codeforces.com/contest/522 A. Reposts time limit per test:1 second memory limit per test:256 megabytes One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started

Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意:给定一颗有根树,在树上下层的节点要给上层节点礼物,根节点的礼物则给慈善会,但是给礼物有个条件就是你不能送你的父节点已经送出的礼物.问满足要求的最少花费. 题解:这个题卡了一段时间,类似于染色问题,可以用树形动态规划求解.因为已知节点个数为N,则我们单个节点的最大花费不会超过log2(N) = 18. 1.