CodeForces NO.549A Face Detection

来源:互联网 发布:ntoskrnl 占用80端口 编辑:程序博客网 时间:2024/05/17 07:43

问题描述:

找2 * 2 的照片,照片由f、a、c、e四个字符组成,可以重叠。详情见原题。

题目链接:CodeForces NO.549A

直接上代码:

#include<iostream>#include<cstdio>#include<cmath>#include<queue>#include<stack>#include<cstring>#include<algorithm>#define INF 0x3f3f3f3f#define MAX 100#define PI 3.1415926using namespace std;int dx[4] = {0, 0, 1, 1}, dy[4] = {0, 1, 0, 1};int main(){    int m, n;    cin >> m >> n;    char arr[MAX][MAX];    int f, a, c, e;    for(int i = 0; i < m; i++)        cin >> arr[i];    int ans = 0;    for(int i = 0; i < m; i++)    {        for(int j = 0; j < n; j++)        {            f = a = c = e = 0;            for(int k = 0; k < 4; k++)            {                int dx1 = i+dx[k], dy1 = j+dy[k];                if(arr[dx1][dy1] == 'f' && dx1 < m && dy1 < n)                    f = 1;                else if(arr[dx1][dy1] == 'a'&& dx1 < m && dy1 < n)                    a = 1;                else if(arr[dx1][dy1] == 'c'&& dx1 < m && dy1 < n)                    c = 1;                else if(arr[dx1][dy1] == 'e'&& dx1 < m && dy1 < n)                    e = 1;            }            if(a + f + c + e == 4)                ans++;        }    }    cout << ans << endl;    return 0;}


1 0