Looksery Cup 2015 A. Face Detection 水题

A. Face Detection

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/549/problem/A

Description

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 Input

4 4
xxxx
xfax
xcex
xxxx

Sample Output

1

HINT

题意

给你n*m的格子,格子里面有字符串,然后问你有多少个2*2的格子里面,含有face

题解:

随便产生一组全排列,然后枚举就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** string s[];
string s1;
int c[]={,,,};
vector<int> a[];
void unit()
{
int i = ;
do
{
for(int j = ; j < ; j++)
a[i].push_back(c[j]);
i++;
} while(next_permutation(c,c + ));
}
int main()
{
//test;
unit;
int n=read(),m=read();
for(int i=;i<n;i++)
cin>>s[i];
s1="face";
int ans=;
int c[]={,,,};
for(int i=;i<n-;i++)
{
for(int j=;j<m-;j++)
{
c[]=,c[]=,c[]=,c[]=;
do{
if(s[i][j]==s1[c[]]&&s[i+][j]==s1[c[]]&&s[i+][j+]==s1[c[]]&&s[i][j+]==s1[c[]])
{
ans++;
break;
}
}while(next_permutation(c,c+));
}
}
cout<<ans<<endl;
}

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.

上一篇:hibernate学习(设计多对多 关系 映射)


下一篇:ThinkPHP 模板substr的截取字符串函数