哈理工OJ 1031 _OOOO_ Problem(简单模拟问题)

OOOO Problem
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 288(96 users) Total Accepted: 90(83 users) Rating: Special Judge: No
Description
Do you know Gobang?
There is a 15 * 15 board and two players drop piece of white or black one by one.
We define a pattern of “+OOOO+” as “Huo 4”.
‘O’ means the piece of you.
‘X’ means the piece of your opponent.
‘+’ means the blank space of the board.
How many “Huo 4” belonging to you in the board ?

Input
Line 1 : A integer T which means there are T test cases following seperated by a blank line.
For each test case, the input will show a 15 * 15 board.

Output
For each test case, output the answer in a line.

Sample Input
2

+++++++++++++++
++OOOO++++++O++
++++++++++++O++
++++++++++++O++
++O+++++++++O++
+++O+++++++++++
++++O++++++++++
+++++O++++++O++
+++++++++++O+++
++++++++++O++++
+++++++++O+++++
+++++++++++++++
+++++++++++++++
+++++++++++++++
+++++++++++++++

++++++++++++X++
++OOOOX+++++O++
++++++++++++O++
++++++++++++O++
++O+++++++++O++
+++O+++++++++++
++++O++++++++X+
+++++O++++++O++
++++++X++++O+++
++++++++++O++++
+++++++++O+++++
+++++++++++++++
+++++++++++++++
+XXXX++++++++++
+++++++++++++++
Sample Output
4
0
本题很简单,看样例就能猜出题目所求是什么。
下面大致说下我的思路吧,假如某个点是“O”,就从这个点为起点开始查找。
看能不能找到符合条件的图形,另外,八个方向只需要找四个就可以了,至于为什么,自己试着思考一下。
下面是AC代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

char a[20][20];
int check(int i,int j,int k,int l,int m)
{
    if(i<0||i>=15||j<0||j>=15||k<0||k>=15||l<0||l>=15||m<0||m>15)
    {
        return 0;
    }
    return 1;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<15;i++)
        {
            scanf("%s",&a[i]);
        }
        int sum=0;
        for(int i=0;i<15;i++)
        {
            for(int j=0;j<15;j++)
            {
                if(a[i][j]=='O')
                {
                    if(check(i-1,i+1,i+2,i+3,i+4)&&a[i-1][j]=='+'&&a[i+1][j]=='O'&&a[i+2][j]=='O'&&a[i+3][j]=='O'&&a[i+4][j]=='+')
                    {
                        sum++;
                    }
                    if(check(j-1,j+1,j+2,j+3,j+4)&&a[i][j-1]=='+'&&a[i][j+1]=='O'&&a[i][j+2]=='O'&&a[i][j+3]=='O'&&a[i][j+4]=='+')
                    {
                        sum++;
                    }
                    if(check(i+1,j-1,i-1,j+1,i-2)&&check(j+2,i-3,j+3,i-4,j+4)&&a[i+1][j-1]=='+'&&a[i-1][j+1]=='O'&&a[i-2][j+2]=='O'&&a[i-3][j+3]=='O'&&a[i-4][j+4]=='+')
                    {
                        sum++;
                    }
                    if(check(i-1,j-1,i+1,j+1,i+2)&&check(j+2,i+3,j+3,i+4,j+4)&&a[i-1][j-1]=='+'&&a[i+1][j+1]=='O'&&a[i+2][j+2]=='O'&&a[i+3][j+3]=='O'&&a[i+4][j+4]=='+')
                    {
                        sum++;
                    }
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值