codeforces 837B Flag of Berland

Camera metadata 阅读详情
B. Flag of Berland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The flag of Berland is such rectangular field n × m that satisfies following conditions:

  • Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
  • Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
  • Each color should be used in exactly one stripe.

You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

Input

The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.

Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.

Output

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

Examples
input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
output
YES
input
4 3
BRG
BRG
BRG
BRG
output
YES
input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
output
NO
input
4 4
RRRR
RRRR
BBBB
GGGG
output
NO
Note

The field in the third example doesn't have three parralel stripes.

Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.



感觉这类题目应该配个图,单纯看英文不怎么好理解。题意就是给出一幅图,包含3中颜色,由3个大写字母表示。问该图是否符合类似于俄罗斯国旗一样的3色分布。

并且认为竖着的也可以。

可以先默认的横着的去check一下,check可以先去判断行数能否整除三然后判断是否是3种颜色都是在行数上连续的,然后看每一行是否都等于该行首。

然后就是把图翻转90度再check,check仍然如上所述,最终得到结果。





#include<bits/stdc++.h>
using namespace std;
char ma[111][111];
char ma1[111][111];
int n,m;
bool ch(int x,int y)
{
	if(x%3!=0)return 0;
	int d=x/3;
	if(ma[0][0]==ma[d][0]||ma[0][0]==ma[d*2][0]||ma[d][0]==ma[d*2][0])
	return 0;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	if(ma[i][j]!=ma[i/d*d][0])return 0;
	return 1;
}
int main(){
   while(cin>>n>>m)
   {
   	int i,j;
   	for(i=0;i<n;i++)
   	cin>>ma[i];
   	if(ch(n,m))
    {
    	cout<<"YES"<<endl;
	}
	else {
		for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		ma1[j][i]=ma[i][j];
		swap(n,m);
		for(i=0;i<n;i++)
		for(j=0;j<m;j++)
		ma[i][j]=ma1[i][j];
		if(ch(n,m))
		{
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	}
   }
	return 0;
}


基于Simulink的六旋翼无人机动力分配仿真建模示例 六旋翼无人机概述特点:高冗余度、增强的负载能力和更好的故障容忍性。关键组件电机与螺旋桨:提供升力和推力。电调(ESC):控制电机转速。IMU(惯性测量单元):包括加速度计和陀螺仪,用于姿态估计。飞控板:处理传感器数据并生成控制信号。应用场景:航拍摄影、农业监测、物流配送等。仿真目标搭建一个简化的六旋翼无人机动力分配模型,涵盖电机驱动、姿态控制及位置控制过程。分析不同条件下的性能指标(如响应时间、稳定性等),并探讨六旋翼无人机的设计优化。 阅读详情

相关推荐

告别外置电阻!揭秘MAX22201集成电流检测的5大设计优势(附PCB布局案例)

本文深入解析MAX22201集成电流检测技术在直流有刷电机驱动中的5大设计优势,包括BOM成本降低、PCB空间优化、动态性能提升等。通过与传统方案(如DRV8871+外置电阻)的实测对比,展示其在高精度电流检测、抗干扰能力和PCB布局简化方面的突破,并附有详细的PCB布局案例和配置指南。

weixin_29189377的博客 248

gom

$BEGIN ;++++++++++++++++++++ 712B584835483739676B383D 306D615548387265507730794C4559794E567775594335673879626B6C6670674745493546784B5336784956343452414474633242764C4C574F644A65486B427579464374375

u013001728的博客 1088

03 Aras Innovator二次开发-服务端方法(二)

Aras Innovator二次开发-服务端方法书写

企业信息化(PLM,ERP.MES) 2022

B. Flag of Berland

B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The flag of Berland is such rectangular f...

weixin_30588907的博客 232

论文理解【LLM-OR】——【OptiCycle/OptiState】Harnessing Language Models as Optimization Modeling Agents

本文使用 agentic 的 “执行—反馈—修正循环” 解决 LLM-OR 问题,以轻量的单智能体交互替代传统方法繁重的多阶段提示与多角色编排,无需额外训练即可提升建模与求解表现

佚失的诗篇 177

告别QXDM:在Android Studio中调试与验证高通NV读写功能的完整流程

本文详细介绍了在Android Studio中调试与验证高通NV分区读写功能的完整流程,替代传统的QXDM工具。通过JNI接口层、HAL服务层和Diag通信层的架构设计,开发者可以在熟悉的IDE环境中高效完成NV操作,包括环境配置、错误处理和性能优化等关键实践。

weixin_27013291的博客 265

Codeforce_837B - Flag of Berland

B. Flag of Berland time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The flag of Berland is such rectangular field n × m that satisfies follo

NITjianbagengmu的博客 521

RK3588与FocalTech触摸屏代码适配全解析:从原理到实战

摘要:本文详细介绍了瑞芯微RK3588处理器与FocalTech触摸屏的适配过程,包括硬件特性、驱动加载、设备树配置和常见问题解决方案。RK3588作为8nm工艺的高性能处理器,具备强大的计算能力和丰富的接口资源;FocalTech触摸屏则采用电容式技术,支持I2C/SPI接口。适配关键步骤包括驱动程序加载、硬件连接检查、设备树配置和内核版本兼容性处理,并提供了代码示例和问题排查方法。随着嵌入式设备智能化发展,该适配技术将持续优化,为智能交互提供更优解决方案。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 281

【CodeForces】837B - Flag of Berland

http://codeforces.com/problemset/problem/837/B一面旗帜上有3种颜色,判断三种颜色构成的图形形状是否相同。#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <map> #include <algorithm> using namespace

西瓜不甜的博客 456

Android CCodec (四) Output Buffer流程分析

Android 多媒体架构 Codec2 Output Buffer

给大佬递杯卡布奇诺的博客 3268

AI智能体丨使用Coze一键生成爆款书单视频,3个月内获赞131.1w!(附保姆级教程)

这篇教程详细介绍了如何使用扣子(Coze)平台的AI智能工作流批量制作爆款书单视频。通过自动化流程,只需1-2分钟即可生成45-50秒的书单视频,效率提升近百倍。工作流包含文案生成、音频合成、图片素材获取、视频剪辑等全流程,支持随机生成8本书单、自动提取金句、智能配音等功能。教程提供了完整的操作步骤,包括剪映草稿配置、特效添加等细节,并附体验链接和示例效果。最终生成的视频包含书单展示、金句字幕、背景音乐等元素,适合书单号运营者快速批量产出内容。

李同学Lino的博客 2361

codeforces837B Flag on Berland

cf837B题解

LiRewriter的博客 525

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

B - Flag of Berland CodeForces - 837B(字符串模拟)

The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters ‘R’, ‘G’ and ‘B’. Flag consists of three equal in wid...

tomjobs的博客 539

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codefroces Educational Round 26 837 B. Flag of Berland

B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The flag of Berland is such rectangular field...

weixin_30853329的博客 170

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

[CF837B] Flag of Berland(乱写)

题意:http://codeforces.com/contest/837/problem/B 判断给定二维阵是否是个条形旗,条形旗符合条件: Flag consists of three colors which correspond to letters'R','G'and'B'. Flag consists of three equal in width and height...

weixin_30363817的博客 147

Educational Codeforces Round 26:B. Flag of Berland

题目: The flag of Berland is such rectangular field n × m that satisfies following conditions: Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of th

愚者 747

codeforces 357B Flag Day

Flag Day time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In Berland, there is the national holiday coming —

Clearlemon 1352

Educational Codeforces Round 26 B - Flag of Berland【思维】

题意:判断一个矩阵 , 是否满足以下条件: 1.仅有R、G、B三种字符 2.三种字符各自连一片,分别和矩形的边平行思路:对n和m是不是3的倍数展开讨论,如果n是3的倍数,那么分成[1,n/3] [n/3+1,2*n/3] [2*n/3+1,n]三个区间进行讨论。m同理。复杂度分析: 图也就100*100 只要不写成死循环就没问题#include <bits/stdc++.h> usin

Haipai1998的博客 312

【codeforce】B. Flag Day

原题:http://codeforces.com/contest/357/problem/B B. Flag Day time limit per test 1 second memory limit per test 256 megabytes input standard input output standard ou

littlekenan的专栏 807

CodeForces 567B Berland National Library【思维】

题目描述 Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading

mengxiang000000 583

Codeforces 1181C-Flag【预处理】【暴力】

题目链接 题意 给一个n * m的网格图,每一个格子有一种颜色(由a~z表示颜色),如果图中有一个子区域是如下图所示,就称作flag,flag的条件: 1,由三层组成,中间层的颜色和上下两层的颜色不同 2,这三层,每层所占行数一样 3,flag的宽度至少是1 问你该图中最多可以组合出几个flag 思路 mapp[i][j]表示在原图中 i,j 处的颜色 block[i][j] 表示在 i,j 处...

weixin_43895356的博客 407

codeforces 1181C Flag

1181C flag 思维深度还是不够,看了出题人的解答才会了。。。 我们预处理出一个四元组(r,c,color,len) r,c行号,列号; len表示宽度为1的从单元格(r,c)向下可以扩展的连续相同颜色的长度; color表示这一段的颜色。 这些信息可以保存在一个二维pair数组中,方便后续使用。 当我们预处理出所有宽度为1的旗帜后便可以以行号为第一层循环,我们将某一块连...

cy41的博客 680

FLAG codeforces 1181C (搜索)

codeforces 1181C (搜索)codeforces 1181C (搜索) codeforces 1181C (搜索) 题意:n*m的图,其中子矩阵由3个等高矩阵自上而下构成(相邻矩阵位置颜色不同),则可以看做一个旗帜,问图中有几个旗帜。 思路:从左上角开始,自上而下遍历,寻找可以实现3块型的宽为1的旗帜,如若可以找到,再向右扩展,若能扩展成功,每扩展一列即可与之前的各列组成新的旗帜,因此自某点*(i,j)*可以扩展的旗帜数量可以如下计算: SUM=1+2+3+4+…+N(N为扩展后的旗帜宽度)

addmission的博客 300

codeforces B. Flag Day 解题报告

题目链接:http://codeforces.com/problemset/problem/357/B 题目意思:输入n个人和m场舞蹈,给出每场舞蹈(只有3个人参与)中参与的舞者的编号,你需要为这些舞者安排衣服的颜色,使得每场舞蹈中3个舞者的颜色都满足是白,红,绿的条件。 特别要注意题目中的两句话:if some dance has two or more dancers from...

weixin_30741653的博客 121

357B - Flag Day

// Problem: B. Flag Day // Contest: Codeforces - Codeforces Round #207 (Div. 2) // URL: https://codeforces.com/problemset/problem/357/B // Memory Limit: 256 MB // Time Limit: 1000 ms // 2022-03-24 16:55:14 // // Powered by CP Editor (https://cpeditor.org)

qq_28409093的博客 167

cf B. Flag Day

http://codeforces.com/contest/357/problem/B 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 100010 5 using namespace std; 6 7 int...

weixin_30707875的博客 134
上一篇: poj 2418 Hardwood Species
下一篇: codeforces 837A Text Volume
threeh20
博客等级 码龄9年 64粉丝 422原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值