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
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[20]; const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** string s[100]; string s1; int c[4]={0,1,2,3}; vector<int> a[50]; void unit() { int i = 0; do { for(int j = 0; j < 4; j++) a[i].push_back(c[j]); i++; } while(next_permutation(c,c + 4)); } int main() { //test; unit; int n=read(),m=read(); for(int i=0;i<n;i++) cin>>s[i]; s1="face"; int ans=0; int c[4]={0,1,2,3}; for(int i=0;i<n-1;i++) { for(int j=0;j<m-1;j++) { c[0]=0,c[1]=1,c[2]=2,c[3]=3; do{ if(s[i][j]==s1[c[0]]&&s[i+1][j]==s1[c[1]]&&s[i+1][j+1]==s1[c[2]]&&s[i][j+1]==s1[c[3]]) { ans++; break; } }while(next_permutation(c,c+4)); } } 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.