当前位置: 首页 > article >正文

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 0xfffffffchar 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;elsecout<<0;return 0;
}

 

http://www.lryc.cn/news/2420969.html

相关文章:

  • 大学生必看的电影
  • yandex网站怎么打不开了?原因及解决方法!
  • 影片:Paycheck
  • SylixOS中断系统分析
  • Android开发——MediaProvider源码分析
  • android中的surface
  • 10款.net 图形插件
  • QQ邮箱模拟登录
  • 安卓唯一标识:IMEI,MEID,MAC地址,Android_id,UUID,OAID
  • 汽车电子常用外围硬件电路设计
  • Instagram 账号被封怎么办?如何申诉拿回账号?
  • JavaScript异步编程学习
  • 使用SharePoint进行编程
  • 系统调用之sys_adjtimex
  • vb.net合伙数据库access(一)——连接数据库
  • Direct3D 9 入门例子程序 圆锥体
  • 使用51单片机来实现步进电机的控制
  • RCS
  • 免费的XP/Vista无损分区软件 EASEUS Partition Master
  • 电脑动态屏保_8款电脑软件,每一款都能让你的电脑更好用
  • 网盘介绍
  • 2层框架结构柱子间距_框架结构的梁柱截面尺寸如何确定
  • Bios读文件与Grub(bootload)和initrd和内核对文件系统驱动的支持
  • Hystrix的降级与熔断测试
  • 3000字计算机领域技术发展,计算机应用技术专业毕业论文3000字
  • troublemaker中文谐音_饿狼传说谐音歌词
  • umts是移动还是联通_网络模式中的UMTS是什么意思?
  • java 开发网站_适用于高级Java开发人员的十大网站
  • ewebeditor编辑器ASP/ASPX/PHP/JSP版本漏洞利用总结及解决方法
  • 汉字编码及区位码查询算法