N - Five-In-a-Row

题目:

Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.

In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.

Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.

Input

You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.

It is guaranteed that in the current arrangement nobody has still won.

Output

Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.

Examples

Input

XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........

Output

YES

Input

XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........

Output

NO

题意:

两个人下五子棋,问你现在让X下一步,X能否赢得比赛;

思路:

这道题就是一道简单的模拟题,我们只需要枚举每一个X能下的位置,然后判断出来同行同列两条对角线上是否有5个X就可以了,主要是注意一些细节;

代码如下:

#include<stdio.h>
#include<string.h>

char a[11][11];
int bfs(int x,int y)
{
    int sum=0;
    int i,j;
    for(i=x;i>=0;i--)//同行;
    {
        if(a[i][y]=='X')
            sum++;
        else
            break;
    }
    for(i=x+1;i<10;i++)
    {
        if(a[i][y]=='X')
            sum++;
        else
            break;
    }
    if(sum>=5)
        return 1;
    sum=0;
    for(j=y;j>=0;j--)//同列;
    {
        if(a[x][j]=='X')
            sum++;
        else
            break;
    }
    for(j=y+1;j<10;j++)
    {
        if(a[x][j]=='X')
            sum++;
        else
            break;
    }
    if(sum>=5)
        return 1;
    sum=0;
    for(i=x,j=y;i>=0,j>=0;i--,j--)//右上角到左下角的对角线;
    {
        if(a[i][j]=='X')
            sum++;
        else
            break;
    }
    for(i=x+1,j=y+1;i<10,j<10;i++,j++)
    {
        if(a[i][j]=='X')
            sum++;
        else
            break;
    }
    if(sum>=5)
        return 1;
    sum=0;
    for(i=x,j=y;i>=0,j<10;i--,j++)//左上角到右下角的对角线;
    {
        if(a[i][j]=='X')
            sum++;
        else
            break;
    }
    for(i=x+1,j=y-1;i<10,j>=0;i++,j--)//注意x,y的值;
    {
        if(a[i][j]=='X')
            sum++;
        else
            break;
    }
    if(sum>=5)
        return 1;
    return 0;
}

int main()
{
    int i,j,kk,flag=0;
    for(i=0;i<10;i++)
        scanf("%s",a[i]);
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            if(a[i][j]=='.')
            {
                a[i][j]='X';
                kk=bfs(i,j);
                if(kk==1)
                {
                    flag=1;
                    printf("YES\n");
                    break;
                }
                else
                a[i][j]='.';//记得还原;
            }
        }
        if(flag==1)
            break;
    }
    if(flag==0)
        printf("NO\n");
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GOAL Perform a Poisson regression to predict the number of people in a househouse based on the age of the head of the household. DATA The Philippine Statistics Authority (PSA) spearheads the Family Income and Expenditure Survey (FIES) nationwide. The survey, which is undertaken every three years, is aimed at providing data on family income and expenditure, including levels of consumption by item of expenditure. The data, from the 2015 FIES, is a subset of 1500 of the 40,000 observations (Philippine Statistics Authority 2015). The data set focuses on five regions: Central Luzon, Metro Manila, Ilocos, Davao, and Visayas. The data is in the file fHH1.csv. Each row is a household, and the follow variables are recorded: • location: where the house is located (Central Luzon, Davao Region, Ilocos Region, Metro Manila, or Visayas) • age: the age of the head of household • total: the number of people in the household other than the head • numLT5: the number in the household under 5 years of age • roof: the type of roof in the household (either Predominantly Light/Salvaged Material, or Predominantly Strong Material. STEPS 1. Read in the dataset. 2. Produce a bar-chart of total 3. Produce a scatter-plot of total against age - add a smoothing line. 4. Fit the Poisson regression total ∼ age 5. Interpret the coefficient of age. 6. Obtain the Pearson residuals. Plot these against age. Is the model adequate? 7. Fit the Poisson regression total ∼ age + age2 8. Repeat the residual plots for the new model. 9. Compare the models using a likelihood ratio test, and AIC. 10. Calculate the predicted values for model M2. What is the age of the head of the household associated with the largest fitted value 使用R语言
05-26

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值