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. Mybatis-对数据库的关联查询

            由于MyBatis逆向工程生成的代码只能进行对单表的操作(功能已经很强大了),但是远远不能满足开发的需要,下面就简单讲解下MyBatis进行关联查询的简单案例. 一.一对一关联查询 1 ...

  2. shell 预定义变量

    echo "上一次后台pid is $!"echo "当前进程pid is $$"echo "last command return code is ...

  3. Sobel边缘检测算法

    索贝尔算子(Sobel operator)主要用作边缘检测,在技术上,它是一离散性差分算子,用来运算图像亮度函数的灰度之近似值.在图像的任何一点使用此算子,将会产生对应的灰度矢量或是其法矢量 Sobe ...

  4. MySQL数据库 | 数据库和数据表的基本操作

    第一篇博文,一个小小的纪念仪式^-^ 以下正文 一.数据库的基本操作 --数据库的操作 --连接数据库 mysql -uroot -p密码 mysql -uroot -pmysql --退出数据库 e ...

  5. LED Decorative Light Supplier - Decorative Use Of LED Light Strips

    Led strip refers to the led assembly in the ribbon of the FPC (flexible circuit board) or PCB hard b ...

  6. HTML学习(4)属性

    属性是HTML元素提供的附加信息,大多数标签都能设置属性,一般位于开始标签,以名称/值的方式出现,例:name="value". 值要放在引号内(单引号.双引号都可以),如果值包含 ...

  7. 【转载】Java容器的线程安全

    转自:http://blog.csdn.net/huilangeliuxin/article/details/12615507 同步容器类 同步容器类包括Vector和Hashtable(二者是早期J ...

  8. 973. 最接近原点的 K 个点

    1.暴力排序,新建节点类重载小于符号排序. class Solution { public: struct comb{ int index,distance; comb():index(0),dist ...

  9. sqlserver 查看视图语句

    本人sql小白一个,在项目中遇到了视图的使用,但是不知道视图的语句怎么查看,所以在网上搜索了一下,查到了一下的查看方式,再次记录一下: 方法一->前提: 已经创建好的视图 sp_helptext ...

  10. 概率 dp lightoj 1395

    dp[k]用类似于低配版的这道题的做法求出,如下: 然后就从k逆推到0就好了 #include<bits/stdc++.h> using namespace std; ; double d ...