A. Find Square
time limit per test:

1 second

memory limit per test:

256 megabytes

input:

standard input

output:

standard output

Consider a table of size n×mn×m, initially fully white. Rows are numbered 11 through nn from top to bottom, columns 11 through mm from left to right. Some square inside the table with odd side length was painted black. Find the center of this square.

Input

The first line contains two integers nn and mm (1≤n,m≤1151≤n,m≤115) — the number of rows and the number of columns in the table.

The ii-th of the next nn lines contains a string of mm characters si1si2…simsi1si2…sim (sijsij is 'W' for white cells and 'B' for black cells), describing the ii-th row of the table.

Output

Output two integers rr and cc (1≤r≤n1≤r≤n, 1≤c≤m1≤c≤m) separated by a space — the row and column numbers of the center of the black square.

Examples
input
5 6
WWBBBW
WWBBBW
WWBBBW
WWWWWW
WWWWWW

output

2 4

input

3 3
WWW
BWW
WWW

output

2 1

Solution1:

#include <iostream>
const int N = 712;
char maze[N][N];
int a, b, r, c, n;
using namespace std;
void dfs(int i, int k)
{
if (maze[i][k] == 'W') maze[i][k] = 'w';
else
{
r += i, c += k; n += 1;
maze[i][k] = 'b';
}
for (int j = 0; j < b; j++)
if (maze[i][j] == 'W' || maze[i][j] == 'B')
dfs(i, j);
}
int main()
{
scanf_s("%d %d", &a, &b);
r = c = n = 0;
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
cin >> maze[i][j];
for (int i = 0; i < a; i++)
if (maze[i][0] == 'W' || maze[i][0] == 'B')
dfs(i, 0); if (n != 0)
{
r /= n, c /= n;
printf("%d %d\n", r + 1, c + 1);
}
return 0;
}

Solution2:

#include <iostream>
const int N = 712;
char maze[N][N];
int a, b, r, c, n;
using namespace std;
int main()
{
r = c = n = 0;
scanf_s("%d %d", &a, &b);
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
{
cin >> maze[i][j];
if (maze[i][j] == 'B')
r += i, c += j, n += 1;
}
if (n != 0)
{
r /= n, c /= n;
printf("%d %d\n", r + 1, c + 1);
}
return 0;
}

  

  

Codeforces AIM Tech Round 5 (rated, Div. 1 + Div. 2)的更多相关文章

  1. Codeforces AIM Tech Round (Div. 2)

    这是我第一次完整地参加codeforces的比赛! 成绩 news standings中第50. 我觉这个成绩不太好.我前半小时就过了前三题,但后面的两题不难,却乱搞了1.5h都没有什么结果,然后在等 ...

  2. AIM Tech Round 5 (rated, Div. 1 + Div. 2) (A, B, E)

    B.Unnatural Conditions 题目链接 : http://codeforces.com/contest/1028/problem/B #include<iostream> ...

  3. AIM Tech Round 5 (rated, Div. 1 + Div. 2) C. Rectangles 【矩阵交集】

    题目传传传送门:http://codeforces.com/contest/1028/problem/C C. Rectangles time limit per test 2 seconds mem ...

  4. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  5. AIM Tech Round 5 (rated, Div. 1 + Div. 2)

    A. Find Square 找到对角线的两个点的坐标,这道题就迎刃而解了. inline void work(int n) { int m; cin >> m; memset(str, ...

  6. AIM Tech Round 5 (rated, Div. 1 + Div. 2) E(思维,构造)

    #include<bits/stdc++.h>using namespace std;long long a[150007];long long ans[150007];int main( ...

  7. AIM Tech Round 5 (rated, Div. 1 + Div. 2) D(SET,思维)

    #include<bits/stdc++.h>using namespace std;const long long mod = 1e9+7;char s[370007][27];long ...

  8. codeforces AIM Tech Round 4 div 2

    A:开个桶统计一下,但是不要忘记k和0比较大小 #include<bits/stdc++.h> using namespace std; ]; ]; int main() { int k; ...

  9. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) 总结】【题解往前或往后翻,不在这】

    又是爆炸的一场 心态有点小崩.但问题不大.. 看A题,一直担心有多个正方形..小心翼翼地看完之后,毅然地交上去了. [00:08] A[Accpted] 然后开始看B题. 觉得和之前做的某题很像,但翻 ...

随机推荐

  1. java基础(三)之面向对象编程

    对象的创建方法 语法: class 类名{ 属性; 方法; } 生成对象的方法 类名 对象名 = new 类名(); Dog dog = new Dog(); 对象的使用方法1.对象.变量;2.对象. ...

  2. Java连载77-Integer常用方法、Integer、int、String三者相互转化、自动装箱、自动拆箱

    一.关于Integer中常用的方法 package com.bjpowernode.java_learning; ​ public class D77_1_ { public static void ...

  3. 如何修改C# winform程序图标

    以Visual Studio 2012 C# Winform程序为例 一.程序内部显示图标的修改方法 在窗体的属性窗口找到icon属性,设置成已经准备好的ico格式的文件,效果如下 二.程序外部显示图 ...

  4. python 数据模型orm

    在__init__.py增加,因为默认的mysqldb不支持python3 import pymysql pymysql.install_as_MySQLdb() 创建表 from django.db ...

  5. asp.net + MVC5 入门完整教程一

    原文链接:https://blog.csdn.net/qq_21419015/article/details/80311918原创凌霜残雪 最后发布于2018-05-14 17:26:30 阅读数 3 ...

  6. MySQL关于GTID的一些功能限制

    参考文献:https://www.cnblogs.com/luckcs/articles/6295992.html 更新非事务引擎: Case重现: master:对一个innodb表做一个多sql更 ...

  7. APP 安全测试

    http://www.cnblogs.com/wetest/p/6694529.html

  8. Codeforces补题2020.2.28(Round624 Div 3)

    A.Add Odd or Subtract Even 签到题~ #include<bits/stdc++.h> using namespace std; int T; int a,b; i ...

  9. 路飞-celery框架

    Celery 官方 Celery 官网:http://www.celeryproject.org/ Celery 官方文档英文版:http://docs.celeryproject.org/en/la ...

  10. Linux - Shell - find - 基础

    概述 find 基础 背景 查找文件 人的记忆能力, 是有限的 计算机里的文件数量, 虽然不是无限, 但是也不少 要去找那些 记不清楚的文件, 必然要用查找 准备 OS centos7 用户 root ...