3.7牛客2021年度训练联盟热身训练赛第一场J.[模拟]

链接:https://ac.nowcoder.com/acm/contest/12606/J
来源:牛客网
 

题目描述

You are given an n−by−n grid where each square is colored either black or white. A grid is correct if all of the following conditions are satisfied: 

  • Every row has the same number of black squares as it has white squares. 

  • Every column has the same number of black squares as it has white squares. 

  • No row or column has 3 or more consecutive squares of the same color. 

Given a grid, determine whether it is correct

输入描述:

The first line contains an integer n(2≤n≤24; n is even ) . Each of the next n lines contains a string of length n consisting solely of the characters ‘B’ and ‘W’, representing the colors of the grid squares.

输出描述:

If the grid iscorrect, print the number 1 on a single line. Otherwise, print the number 0 on a single line.

示例1

输入

复制

4
WBBW
WBWB
BWWB
BWBW

输出

复制

1

示例2

输入

复制

4
BWWB
BWBB
WBBW
WBWW

输出

复制

0

示例3

输入

复制

6
BWBWWB
WBWBWB
WBBWBW
BBWBWW
BWWBBW
WWBWBB

输出

复制

0

示例4

输入

复制

6
WWBBWB
BBWWBW
WBWBWB
BWBWBW
BWBBWW
WBWWBB

输出

复制

1
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 101000;
#define inf 0xfffffff

char ma[30][30];

int col[30],row[30];

int main()
{
    int n;
    cin>>n;
    bool is_correct=true;
    memset(col,0,sizeof(col));
    memset(row,0,sizeof(row));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>ma[i][j];
            if(ma[i][j]=='W')
            {
                row[i]++;
                col[j]++;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if((ma[i][j]==ma[i][j+1])&&(ma[i][j+1]==ma[i][j+2]))
            {
                is_correct=false;
                //cout<<1<<endl;
                break;
            }
        }
    }
    for(int j=0;j<n;j++)
    {
        for(int i=0;i<n;i++)
        {
            if((ma[i][j]==ma[i+1][j])&&(ma[i+1][j]==ma[i+2][j]))
            {
                is_correct=false;
                //cout<<2<<endl;
                break;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(row[i]!=(n-row[i]))
        {
            is_correct=false;
            break;
        }
        if(col[i]!=(n-col[i]))
        {
            is_correct=false;
            //cout<<4<<endl;
            break;
        }
    }
    if(is_correct==true)
        cout<<1;
    else
        cout<<0;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值